diff --git a/NEWS.md b/NEWS.md index f83b34cf6adf4102b044843df6db0bccbbb455de..025519f7b365a1f180655e23a7b3a438809ba0b9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # CSIndicators 1.1.2 (Release date: 2025-03-27) ### Fixes +- Avoid using 'builtin' type functions in call to multiApply::Apply() - CST_PeriodStandardization: Set na.rm = TRUE when replacing infinite values with maximum/minimum period values - CST_PeriodPET(): Add longname and other variable metadata - Not drop singleton time dimensions in diff --git a/R/MergeRefToExp.R b/R/MergeRefToExp.R index 6d9fd6e88104d58c871254ac52171b4e4fce115d..69f722b7934de0df3185b4042304bd832946dc84 100644 --- a/R/MergeRefToExp.R +++ b/R/MergeRefToExp.R @@ -184,8 +184,10 @@ CST_MergeRefToExp <- function(data1, data2, start1 = NULL, end1 = NULL, names(dim(dates2)) <- time_dim } } - res <- Apply(list(dates1, dates2), target_dims = time_dim, - 'c', output_dims = time_dim, ncores = ncores)$output1 + res <- Apply(list(dates1, dates2), + target_dims = time_dim, + fun = function(x, ...) {c(x, ...)}, + output_dims = time_dim, ncores = ncores)$output1 if (inherits(dates1, 'Date')) { data1$attrs$Dates <- as.Date(res, origin = '1970-01-01') @@ -421,7 +423,8 @@ MergeRefToExp <- function(data1, data2, dates1 = NULL, dates2 = NULL, } } - data1 <- Apply(list(data1, data2), target_dims = time_dim, fun = 'c', + data1 <- Apply(list(data1, data2), target_dims = time_dim, + fun = function(x, ...) {c(x, ...)}, output_dims = time_dim, ncores = ncores)$output1 if (all(names(dim(data1)) %in% data1dims)) { diff --git a/R/PeriodAccumulation.R b/R/PeriodAccumulation.R index 424a1c86b44a57be3cb88045a041b46991bc8417..2adf45f78da157b89aecaa4978a4f3090e2e9de4 100644 --- a/R/PeriodAccumulation.R +++ b/R/PeriodAccumulation.R @@ -274,7 +274,7 @@ PeriodAccumulation <- function(data, dates = NULL, start = NULL, end = NULL, if (is.null(rollwidth)) { # period accumulation - total <- Apply(list(data), target_dims = time_dim, fun = sum, + total <- Apply(list(data), target_dims = time_dim, fun = function(...) {sum(...)}, na.rm = na.rm, ncores = ncores)$output1 } else { # rolling accumulation @@ -338,7 +338,9 @@ PeriodAccumulation <- function(data, dates = NULL, start = NULL, end = NULL, } } - data_accum <- rollapply(data = data_vector, width = rollwidth, FUN = sum, na.rm = na.rm) + data_accum <- rollapply(data = data_vector, width = rollwidth, + FUN = function(...) {sum(...)}, + na.rm = na.rm) if (!forwardroll) { data_accum <- c(rep(NA, rollwidth-1), data_accum) } else { diff --git a/R/PeriodMax.R b/R/PeriodMax.R index b028d1014bbf119a415703d9f184ecf0ef85a738..46f09846517677865317337b5dce9beb6415df52 100644 --- a/R/PeriodMax.R +++ b/R/PeriodMax.R @@ -206,11 +206,10 @@ PeriodMax <- function(data, dates = NULL, start = NULL, end = NULL, } } } - total <- Apply(list(data), target_dims = time_dim, fun = max, + total <- Apply(list(data), target_dims = time_dim, fun = function(...) {max(...)}, na.rm = na.rm, ncores = ncores)$output1 dim(total) <- c(dim(total), setNames(1, time_dim)) return(total) } - diff --git a/R/PeriodMin.R b/R/PeriodMin.R index a9be2d5436cb30e67edd87e9eb13ef3e8ce8caac..52fb10a91cef7d805d3ff0ac0863e07d6e35b2f9 100644 --- a/R/PeriodMin.R +++ b/R/PeriodMin.R @@ -206,7 +206,8 @@ PeriodMin <- function(data, dates = NULL, start = NULL, end = NULL, } } } - total <- Apply(list(data), target_dims = time_dim, fun = min, + total <- Apply(list(data), target_dims = time_dim, + fun = function(...) {min(...)}, na.rm = na.rm, ncores = ncores)$output1 dim(total) <- c(dim(total), setNames(1, time_dim)) return(total) diff --git a/R/SelectPeriodOnData.R b/R/SelectPeriodOnData.R index 1cc2792ed9a1bb3cdd909fd99a4a1a1db6402559..731abb5c47320617b81e9b4816acf9b776708c78 100644 --- a/R/SelectPeriodOnData.R +++ b/R/SelectPeriodOnData.R @@ -121,7 +121,7 @@ SelectPeriodOnData <- function(data, dates, start, end, ncores = ncores)$output1 # when 29Feb is included the length of the output changes: regular <- Apply(list(res), target_dims = time_dim, - fun = sum, ncores = ncores)$output1 + fun = function(...) {sum(...)}, ncores = ncores)$output1 dims <- dim(data) dims[names(dims) == time_dim] <- max(regular) if (any(regular != max(regular))) { diff --git a/R/SelectPeriodOnDates.R b/R/SelectPeriodOnDates.R index 550aad94ff28525af253b13a68b80d785f10725f..b95c50912c7f7cacb7b26051957bdb9083dec03b 100644 --- a/R/SelectPeriodOnDates.R +++ b/R/SelectPeriodOnDates.R @@ -53,7 +53,7 @@ SelectPeriodOnDates <- function(dates, start, end, } # when 29Feb is included the length of the output changes: regular <- Apply(list(res), target_dims = time_dim, - fun = sum, ncores = ncores)$output1 + fun = function(...) {sum(...)}, ncores = ncores)$output1 dims <- dim(dates) dims[names(dims) == time_dim] <- max(regular) if (any(regular != max(regular))) {