diff --git a/.buildlibrary b/.buildlibrary index cd07bd4..109b060 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '62149654' +ValidationKey: '62462280' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 62f13da..7ccf77e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,7 @@ repos: - id: mixed-line-ending - repo: https://github.com/lorenzwalthert/precommit - rev: 7910e0323d7213f34275a7a562b9ef0fde8ce1b9 # frozen: v0.4.2 + rev: bae853d82da476eee0e0a57960ee6b741a3b3fb7 # frozen: v0.4.3 hooks: - id: parsable-R - id: deps-in-desc diff --git a/CITATION.cff b/CITATION.cff index 86df521..ae1ba94 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,8 +2,8 @@ cff-version: 1.2.0 message: If you use this software, please cite it using the metadata from this file. type: software title: 'madrat: May All Data be Reproducible and Transparent (MADRaT) *' -version: 3.12.2 -date-released: '2024-07-03' +version: 3.13.0 +date-released: '2024-08-21' abstract: Provides a framework which should improve reproducibility and transparency in data processing. It provides functionality such as automatic meta data creation and management, rudimentary quality management, data caching, work-flow management diff --git a/DESCRIPTION b/DESCRIPTION index 37618b5..97633ab 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: madrat Title: May All Data be Reproducible and Transparent (MADRaT) * -Version: 3.12.2 -Date: 2024-07-03 +Version: 3.13.0 +Date: 2024-08-21 Authors@R: c( person("Jan Philipp", "Dietrich", , "dietrich@pik-potsdam.de", role = c("aut", "cre"), comment = c(affiliation = "Potsdam Institute for Climate Impact Research", ORCID = "0000-0002-4309-6431")), diff --git a/R/toolAggregate.R b/R/toolAggregate.R index d5fc9bd..f1d556a 100644 --- a/R/toolAggregate.R +++ b/R/toolAggregate.R @@ -64,7 +64,7 @@ #' @param verbosity Verbosity level of messages coming from the function: -1 = error, #' 0 = warning, 1 = note, 2 = additional information, >2 = no message #' @param zeroWeight Describes how a weight sum of 0 for a category/aggregation target should be treated. -#' "allow" means it is accepted (dangerous), "warn" throws a warning, "stop" throws an error. +#' "allow" accepts it and returns 0 (dangerous), "setNA" returns NA, "warn" throws a warning, "stop" throws an error. #' @return the aggregated data in magclass format #' @author Jan Philipp Dietrich, Ulrich Kreidenweis #' @export @@ -254,12 +254,14 @@ toolAggregate <- function(x, rel, weight = NULL, from = NULL, to = NULL, dim = 1 if (zeroWeight == "warn") { msg <- paste0("Weight sum is 0, so cannot normalize and will return 0 for some ", "aggregation targets. This changes the total sum of the magpie object! ", - 'If this is really intended set zeroWeight = "allow".') + 'If this is really intended set zeroWeight = "allow", or "setNA" to return NA.') if (Sys.Date() < "2024-07-01") { message(msg) } else { warning(msg) } + } else if (zeroWeight == "setNA") { + tmp[tmp == 0] <- NA } else { stop("Weight sum is 0, so cannot normalize. This changes the total sum of the magpie object!") } diff --git a/README.md b/README.md index 57be542..c2232cb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # May All Data be Reproducible and Transparent (MADRaT) * -R package **madrat**, version **3.12.2** +R package **madrat**, version **3.13.0** [![CRAN status](https://www.r-pkg.org/badges/version/madrat)](https://cran.r-project.org/package=madrat) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1115490.svg)](https://doi.org/10.5281/zenodo.1115490) [![R build status](https://github.com/pik-piam/madrat/workflows/check/badge.svg)](https://github.com/pik-piam/madrat/actions) [![codecov](https://codecov.io/gh/pik-piam/madrat/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/madrat) [![r-universe](https://pik-piam.r-universe.dev/badges/madrat)](https://pik-piam.r-universe.dev/builds) @@ -55,7 +55,7 @@ In case of questions / problems please contact Jan Philipp Dietrich , R package version 3.12.2, . +Dietrich J, Baumstark L, Wirth S, Giannousakis A, Rodrigues R, Bodirsky B, Leip D, Kreidenweis U, Klein D, Sauer P (2024). _madrat: May All Data be Reproducible and Transparent (MADRaT)_. doi:10.5281/zenodo.1115490 , R package version 3.13.0, . A BibTeX entry for LaTeX users is @@ -64,7 +64,7 @@ A BibTeX entry for LaTeX users is title = {madrat: May All Data be Reproducible and Transparent (MADRaT)}, author = {Jan Philipp Dietrich and Lavinia Baumstark and Stephen Wirth and Anastasis Giannousakis and Renato Rodrigues and Benjamin Leon Bodirsky and Debbora Leip and Ulrich Kreidenweis and David Klein and Pascal Sauer}, year = {2024}, - note = {R package version 3.12.2}, + note = {R package version 3.13.0}, url = {https://github.com/pik-piam/madrat}, doi = {10.5281/zenodo.1115490}, } diff --git a/man/toolAggregate.Rd b/man/toolAggregate.Rd index 1572e2d..24b710c 100644 --- a/man/toolAggregate.Rd +++ b/man/toolAggregate.Rd @@ -75,7 +75,7 @@ will lead to summation.} 0 = warning, 1 = note, 2 = additional information, >2 = no message} \item{zeroWeight}{Describes how a weight sum of 0 for a category/aggregation target should be treated. -"allow" means it is accepted (dangerous), "warn" throws a warning, "stop" throws an error.} +"allow" accepts it and returns 0 (dangerous), "setNA" returns NA, "warn" throws a warning, "stop" throws an error.} } \value{ the aggregated data in magclass format diff --git a/tests/testthat/test-toolAggregate.R b/tests/testthat/test-toolAggregate.R index ccf79d4..4408180 100644 --- a/tests/testthat/test-toolAggregate.R +++ b/tests/testthat/test-toolAggregate.R @@ -224,5 +224,8 @@ test_that("columns with only zeros in weight produce a warning", { weight[, , ] <- 0 expect_warning(toolAggregate(pm, rel, weight = weight), "Weight sum is 0") expect_error(toolAggregate(pm, rel, weight = weight, zeroWeight = "stop"), "Weight sum is 0") - expect_silent(toolAggregate(pm, rel, weight = weight, zeroWeight = "allow")) + expect_silent(allZero <- toolAggregate(pm, rel, weight = weight, zeroWeight = "allow")) + expect_true(all(allZero == 0)) + expect_silent(setNA <- toolAggregate(pm, rel, weight = weight, zeroWeight = "setNA")) + expect_true(all(is.na(setNA))) })