Skip to content

Commit 9c24888

Browse files
committed
Merge branch 'fix_partial_match_warnings' into 'master'
FIxed partial matching in write_config See merge request lpjml/lpjmlkit!108
2 parents 26f605c + 55e8eee commit 9c24888

File tree

15 files changed

+83
-72
lines changed

15 files changed

+83
-72
lines changed

.buildlibrary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ValidationKey: '3589192'
1+
ValidationKey: '3612220'
22
AutocreateReadme: yes
33
AcceptedWarnings:
44
- 'Warning: package ''.*'' was built under R version'

.github/workflows/check.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@ jobs:
3535
# gms, goxygen, GDPuc) will usually have an outdated binary version
3636
# available; by using extra-packages we get the newest version
3737

38-
- uses: actions/setup-python@v5
39-
with:
40-
python-version: 3.9
41-
42-
- name: Install python dependencies if applicable
43-
run: |
44-
[ -f requirements.txt ] && python -m pip install --upgrade pip wheel || true
45-
[ -f requirements.txt ] && pip install -r requirements.txt || true
46-
4738
- name: Run pre-commit checks
4839
shell: bash
4940
run: |

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ cff-version: 1.2.0
22
message: If you use this software, please cite it using the metadata from this file.
33
type: software
44
title: 'lpjmlkit: Toolkit for Basic LPJmL Handling'
5-
version: 1.7.8
6-
date-released: '2025-03-17'
5+
version: 1.7.9
6+
date-released: '2025-04-02'
77
abstract: A collection of basic functions to facilitate the work with the Dynamic
88
Global Vegetation Model (DGVM) Lund-Potsdam-Jena managed Land (LPJmL) hosted at
99
the Potsdam Institute for Climate Impact Research (PIK). It provides functions for

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: lpjmlkit
22
Type: Package
33
Title: Toolkit for Basic LPJmL Handling
4-
Version: 1.7.8
4+
Version: 1.7.9
55
Authors@R: c(
66
person("Jannes", "Breier", , "jannesbr@pik-potsdam.de", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9055-6904")),
77
person("Sebastian","Ostberg", , "ostberg@pik-potsdam.de", role = "aut", comment = c(ORCID = "0000-0002-2368-7015")),
@@ -56,4 +56,4 @@ Suggests:
5656
R6
5757
Config/testthat/edition: 3
5858
VignetteBuilder: knitr
59-
Date: 2025-03-17
59+
Date: 2025-04-02

R/LPJmLData_as.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ LPJmLData$set(
451451
multi_layer <- multi_dims[which(multi_dims != "cell")]
452452

453453
tmp_rast <- terra::rast(tmp_rast,
454-
nl = dim(data_subset$data)[multi_layer],
454+
nlyrs = dim(data_subset$data)[multi_layer],
455455
vals = NA)
456456

457457
names(tmp_rast) <- dimnames(data_subset$data)[[multi_layer]]
@@ -590,8 +590,8 @@ create_tmp_raster <- function(data_subset, is_terra = FALSE) {
590590

591591
if (is_terra) {
592592
tmp_raster <- terra::rast(
593-
res = c(data_subset$meta$cellsize_lon,
594-
data_subset$meta$cellsize_lat),
593+
resolution = c(data_subset$meta$cellsize_lon,
594+
data_subset$meta$cellsize_lat),
595595
xmin = grid_extent[1, 1],
596596
xmax = grid_extent[2, 1],
597597
ymin = grid_extent[1, 2],
@@ -602,8 +602,8 @@ create_tmp_raster <- function(data_subset, is_terra = FALSE) {
602602

603603
} else {
604604
tmp_raster <- raster::raster(
605-
res = c(data_subset$meta$cellsize_lon,
606-
data_subset$meta$cellsize_lat),
605+
resolution = c(data_subset$meta$cellsize_lon,
606+
data_subset$meta$cellsize_lat),
607607
xmn = grid_extent[1, 1],
608608
xmx = grid_extent[2, 1],
609609
ymn = grid_extent[1, 2],

R/LPJmLGridData.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ LPJmLGridData <- R6::R6Class( # nolint:object_name_linter
123123

124124
# Update grid meta data
125125
self$.__set_data__(
126-
drop_omit(self$data, omit = "cell")
126+
drop_omit(self$data, omit_dim = "cell")
127127
)
128128

129129
# Update grid meta data

R/get_cellindex.R

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
#' to correct it.
1010
#'
1111
#' @param grid_filename A string representing the grid file name.
12-
#' @param extent A numeric vector (lonmin, lonmax, latmin, latmax) containing the
13-
#' longitude and latitude boundaries between which values included in the subset.
14-
#' @param coordinates A list of two named (lon, lat) numeric vectors representing the coordinates.
15-
#' @param shape A terra SpatVector object in the WGS 84 coordinate reference system
16-
#' representing the shape to subset the grid.
17-
#' @param simplify A logical indicating whether to simplify the output to a vector.
12+
#' @param extent A numeric vector (lonmin, lonmax, latmin, latmax) containing
13+
#' the longitude and latitude boundaries between which values included in the
14+
#' subset.
15+
#' @param coordinates A list of two named (lon, lat) numeric vectors
16+
#' representing the coordinates.
17+
#' @param shape A terra SpatVector object in the WGS 84 coordinate reference
18+
#' system representing the shape to subset the grid.
19+
#' @param simplify A logical indicating whether to simplify the output to a
20+
#' vector.
1821
#'
1922
#'
2023
#' @return Either an LPJmLData object containing the grid or a vector subsetted
@@ -25,7 +28,8 @@
2528
#' \dontrun{
2629
#' get_cellindex(
2730
#' grid_filename = "my_grid.bin.json",
28-
#' extent = c(-123.25, -122.75, 49.25, 49.75) # (lonmin, lonmax, latmin, latmax)
31+
#' extent = c(-123.25, -122.75, 49.25, 49.75) # (lonmin, lonmax, latmin,
32+
#' latmax)
2933
#' )
3034
#' get_cellindex(
3135
#' grid_filename = "my_grid.bin.json",
@@ -39,7 +43,8 @@
3943
#'
4044
#' If an `extent` is provided, the function filters the cells to include only
4145
#' those within the specified longitude and latitude range. The `extent` should
42-
#' be a numeric vector of length 4 in the form c(lonmin, lonmax, latmin, latmax).
46+
#' be a numeric vector of length 4 in the form c(lonmin, lonmax, latmin,
47+
#' latmax).
4348
#'
4449
#' If a list of `coordinates` is provided, the function filters the cells to
4550
#' include only those that match the specified coordinates. The `coordinates`
@@ -58,7 +63,10 @@
5863
#' specific error messages for different error conditions. For example, it
5964
#' checks if the `grid_filename` exists, if the `extent` vector has the correct
6065
#' length, and if the `coordinates` list contains two vectors of equal length.
61-
get_cellindex <- function(grid_filename, extent = NULL, coordinates = NULL, shape = NULL, simplify = TRUE) {
66+
get_cellindex <- function(grid_filename, extent = NULL,
67+
coordinates = NULL,
68+
shape = NULL,
69+
simplify = TRUE) {
6270
# check if filepath is valid
6371
check_filepath(grid_filename)
6472
# check if (only) one of extent or coordinates is provided
@@ -85,7 +93,8 @@ get_cellindex <- function(grid_filename, extent = NULL, coordinates = NULL, shap
8593
lon_range <- range(cells$lon)
8694
lat_range <- range(cells$lat)
8795

88-
# Check if extent values are within the longitude and latitude range in the cells
96+
# Check if extent values are within the longitude and latitude range in the
97+
# cells
8998
if (!is.null(extent)) {
9099
cells$cellindex <- as.numeric(row.names(cells)) + 1
91100

@@ -118,7 +127,8 @@ get_cellindex <- function(grid_filename, extent = NULL, coordinates = NULL, shap
118127
}
119128
}
120129

121-
# Check if coordinates are within the longitude and latitude range in the cells
130+
# Check if coordinates are within the longitude and latitude range in the
131+
# cells
122132
if (!is.null(coordinates)) {
123133
out_of_bounds <- coordinates[[1]] < lon_range[1] |
124134
coordinates[[1]] > lon_range[2] |
@@ -161,7 +171,8 @@ get_cellindex <- function(grid_filename, extent = NULL, coordinates = NULL, shap
161171
dplyr::select("x", "y")
162172

163173
cells <- grid_lonlat |>
164-
subset(coordinates = lapply(list(lon = cell_coords$x, lat = cell_coords$y),
174+
subset(coordinates = lapply(list(lon = cell_coords$x,
175+
lat = cell_coords$y),
165176
FUN = as.character))
166177
}
167178

@@ -189,7 +200,8 @@ check_extent <- function(extent) {
189200
stop("extent must be a numeric vector of length 4.")
190201
}
191202

192-
# check if character vector present and convert to numeric (to be consistent with coordinates) # nolint
203+
# check if character vector present and convert to numeric (to be consistent
204+
# with coordinates)
193205
if (is.character(extent)) {
194206
extent <- as.numeric(extent)
195207
}
@@ -207,7 +219,8 @@ check_extent <- function(extent) {
207219
# Check if both extent and coordinates are provided
208220
check_multiple <- function(extent, coordinates, shape) {
209221
if (is.null(extent) && is.null(coordinates) && is.null(shape)) {
210-
warning("Neither extent, coordinates or shape provided. Full grid will be returned.")
222+
warning("Neither extent, coordinates or shape provided.",
223+
" Full grid will be returned.")
211224
}
212225
if ((!is.null(extent) && !is.null(coordinates)) ||
213226
(!is.null(extent) && !is.null(shape)) ||
@@ -236,15 +249,17 @@ correct_extent <- function(extent) {
236249
extent
237250
}
238251

239-
# Check if the coordinates are a list of two numeric vectors and of equal length
252+
# Check if the coordinates are a list of two numeric vectors and of equal
253+
# length
240254
check_coordinates <- function(coordinates) {
241255
if (!is.list(coordinates) || length(coordinates) != 2) {
242256
stop("coordinates must be a list of two vectors.")
243257
}
244258

245259
coordinates <- lapply(coordinates, function(coord) {
246260
if (!is.numeric(coord)) {
247-
warning("Non-numeric coordinates detected, attempting to convert to numeric.")
261+
warning("Non-numeric coordinates detected,",
262+
" attempting to convert to numeric.")
248263
coord <- as.numeric(coord)
249264
if (any(is.na(coord))) {
250265
stop("Unable to convert all coordinates to numeric.")

R/read_config.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ read_config <- function(filename,
5555
# Read compiled config files. detect_io_type returns "json" for pure JSON without
5656
# comments.
5757
if (tolower(file_type) == "json") {
58-
tmp_json <- jsonlite::read_json(path = filename, simplify = FALSE)
58+
tmp_json <- jsonlite::read_json(path = filename, simplifyVector = FALSE)
5959

6060
} else {
6161
# Read compilable cjson or js files - the standard default config files. These

R/read_meta.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ read_meta <- function(filename, ...) {
3636

3737
# Meta (JSON) file handling
3838
if (file_type == "meta") {
39-
meta_object <- jsonlite::read_json(path = filename, simplify = TRUE) %>%
39+
meta_object <- jsonlite::read_json(path = filename, simplifyVector = TRUE) %>%
4040
LPJmLMetaData$new(data_dir = pathname)
4141

42-
# Handling of input or output file containing a header
42+
# Handling of input or output file containing a header
4343
} else if (file_type == "clm") {
4444
header <- read_header(filename, ...)
4545
additional_attributes <- list(
@@ -53,7 +53,7 @@ read_meta <- function(filename, ...) {
5353
data_dir = pathname
5454
)
5555

56-
# Other formats are not supported yet
56+
# Other formats are not supported yet
5757
} else {
5858
stop("Non readable (meta) file format.")
5959
}

R/write_config.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ parse_config <- function(path,
598598
),
599599
wd = path,
600600
cleanup_tree = TRUE)$stdout %>%
601-
jsonlite::parse_json(simplify = FALSE)
601+
jsonlite::parse_json(simplifyVector = FALSE)
602602

603603
tmp_json
604604
}

0 commit comments

Comments
 (0)