From 03652da0d181553b2cd1c0bd28405194da62c455 Mon Sep 17 00:00:00 2001 From: Michaja Pehl Date: Tue, 28 May 2024 12:31:05 +0200 Subject: [PATCH 1/3] extend mbind() error message to print elements of differing dimensions --- R/mbind.R | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/R/mbind.R b/R/mbind.R index d19c1d76..bb4eaba0 100644 --- a/R/mbind.R +++ b/R/mbind.R @@ -76,9 +76,49 @@ mbind <- function(...) { #nolint " data objects! Cannot handle this case!") } - if (diffspat && difftemp) stop("Cannot handle objects! Spatial as well as temporal dimensions differ!") - if (difftemp && diffdata) stop("Cannot handle objects! Data as well as temporal dimensions differ!") - if (diffdata && diffspat) stop("Cannot handle objects! Data as well as spatial dimensions differ!") + diffall <- c('spatial' = diffspat, 'temporal' = difftemp, 'data' = diffdata) + if (1 < sum(diffall)) { + msg <- c("Cannot handle objects!", + paste( + paste(head(names(diffall)[diffall], n = -1), + collapse = ", "), + tail(names(diffall)[diffall], n = 1), + sep = " as well as "), + "dimensions differ!") + substr(msg[2], 1, 1) <- toupper(substr(msg[2], 1, 1)) + + msg <- paste( + c(paste(msg, collapse = " "), + " Differences from first mbind() input:", + vapply(which(diffall), function(i) { + + lhs <- getItems(inputs[[1]], dim = i) + rhs <- Reduce(union, lapply(tail(inputs, n = -1), getItems, dim = i)) + + # do a kind of three-way diff + diff <- list('missing' = setdiff(lhs, rhs), + ' having' = intersect(lhs, rhs), + ' adding' = setdiff(rhs, lhs)) + + diff <- lapply(diff, function(x) { + if (4 < length(x)) { # shorten to four elements, like str() does + x <- c(paste0("`", x[1:4], "`"), "...") + } else if (0 < length(x)) { + x <- paste0("`", x, "`") + } + return(paste(x, collapse = ", ")) + }) + + # paste diff + d <- nzchar(diff) + paste(c(paste0(" ", names(diffall)[i], ":"), + paste(paste0(" ", names(diff)[d], ":"), diff[d])), + collapse = "\n") + }, character(1))), + collapse = "\n") + stop(msg) + } + if (difftemp) { if (length(years) != length(unique(years))) stop("Some years occur more than once!", " Cannot handle this case!") From 52c66fc5c229ec1ed27c86dfc4e60a5daf386af5 Mon Sep 17 00:00:00 2001 From: Michaja Pehl Date: Tue, 28 May 2024 12:40:43 +0200 Subject: [PATCH 2/3] Sacrifice at the altar of all-mighty lintr! --- R/mbind.R | 62 +++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/R/mbind.R b/R/mbind.R index bb4eaba0..dad96b04 100644 --- a/R/mbind.R +++ b/R/mbind.R @@ -76,46 +76,46 @@ mbind <- function(...) { #nolint " data objects! Cannot handle this case!") } - diffall <- c('spatial' = diffspat, 'temporal' = difftemp, 'data' = diffdata) + diffall <- c("spatial" = diffspat, "temporal" = difftemp, "data" = diffdata) if (1 < sum(diffall)) { msg <- c("Cannot handle objects!", - paste( - paste(head(names(diffall)[diffall], n = -1), - collapse = ", "), - tail(names(diffall)[diffall], n = 1), - sep = " as well as "), + paste(paste(head(names(diffall)[diffall], n = -1), + collapse = ", "), + tail(names(diffall)[diffall], n = 1), + sep = " as well as "), "dimensions differ!") substr(msg[2], 1, 1) <- toupper(substr(msg[2], 1, 1)) - msg <- paste( - c(paste(msg, collapse = " "), - " Differences from first mbind() input:", - vapply(which(diffall), function(i) { + msg <- paste(c(paste(msg, collapse = " "), + " Differences from first mbind() input:", + vapply(which(diffall), function(i) { - lhs <- getItems(inputs[[1]], dim = i) - rhs <- Reduce(union, lapply(tail(inputs, n = -1), getItems, dim = i)) + lhs <- getItems(inputs[[1]], dim = i) + rhs <- Reduce(union, lapply(tail(inputs, n = -1), + getItems, dim = i)) - # do a kind of three-way diff - diff <- list('missing' = setdiff(lhs, rhs), - ' having' = intersect(lhs, rhs), - ' adding' = setdiff(rhs, lhs)) + # do a kind of three-way diff + diff <- list("missing" = setdiff(lhs, rhs), + " having" = intersect(lhs, rhs), + " adding" = setdiff(rhs, lhs)) - diff <- lapply(diff, function(x) { - if (4 < length(x)) { # shorten to four elements, like str() does - x <- c(paste0("`", x[1:4], "`"), "...") - } else if (0 < length(x)) { - x <- paste0("`", x, "`") - } - return(paste(x, collapse = ", ")) - }) + diff <- lapply(diff, function(x) { + if (4 < length(x)) { + # shorten to four elements, like str() does + x <- c(paste0("`", x[1:4], "`"), "...") + } else if (0 < length(x)) { + x <- paste0("`", x, "`") + } + return(paste(x, collapse = ", ")) + }) - # paste diff - d <- nzchar(diff) - paste(c(paste0(" ", names(diffall)[i], ":"), - paste(paste0(" ", names(diff)[d], ":"), diff[d])), - collapse = "\n") - }, character(1))), - collapse = "\n") + # paste diff + d <- nzchar(diff) + paste(c(paste0(" ", names(diffall)[i], ":"), + paste(paste0(" ", names(diff)[d], ":"), + diff[d])), + collapse = "\n") + }, character(1))), collapse = "\n") stop(msg) } From 960602656367203addde2bac2f9d08e0271ea5f5 Mon Sep 17 00:00:00 2001 From: Michaja Pehl Date: Tue, 28 May 2024 12:46:43 +0200 Subject: [PATCH 3/3] lucode hubbub --- .buildlibrary | 2 +- CITATION.cff | 4 ++-- DESCRIPTION | 4 ++-- README.md | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index acda8078..22e0c9bf 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '122203328' +ValidationKey: '1222642778871' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/CITATION.cff b/CITATION.cff index 0b185c8f..47041c4f 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: 'magclass: Data Class and Tools for Handling Spatial-Temporal Data' -version: 6.15.2 -date-released: '2024-05-21' +version: 6.15.2.9001 +date-released: '2024-05-28' abstract: Data class for increased interoperability working with spatial-temporal data together with corresponding functions and methods (conversions, basic calculations and basic data manipulation). The class distinguishes between spatial, temporal diff --git a/DESCRIPTION b/DESCRIPTION index 824c547e..8156dc56 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: magclass Title: Data Class and Tools for Handling Spatial-Temporal Data -Version: 6.15.2 -Date: 2024-05-21 +Version: 6.15.2.9001 +Date: 2024-05-28 Authors@R: c( person("Jan Philipp", "Dietrich", , "dietrich@pik-potsdam.de", comment = c(affiliation = "Potsdam Institute for Climate Impact Research", ORCID = "0000-0002-4309-6431"), role = c("aut", "cre")), diff --git a/README.md b/README.md index c125de92..1a838e62 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Data Class and Tools for Handling Spatial-Temporal Data -R package **magclass**, version **6.15.2** +R package **magclass**, version **6.15.2.9001** [![CRAN status](https://www.r-pkg.org/badges/version/magclass)](https://cran.r-project.org/package=magclass) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1158580.svg)](https://doi.org/10.5281/zenodo.1158580) [![R build status](https://github.com/pik-piam/magclass/workflows/check/badge.svg)](https://github.com/pik-piam/magclass/actions) [![codecov](https://codecov.io/gh/pik-piam/magclass/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/magclass) [![r-universe](https://pik-piam.r-universe.dev/badges/magclass)](https://pik-piam.r-universe.dev/builds) @@ -56,7 +56,7 @@ In case of questions / problems please contact Jan Philipp Dietrich . +Dietrich J, Bodirsky B, Bonsch M, Humpenoeder F, Bi S, Karstens K, Leip D, Sauer P (2024). _magclass: Data Class and Tools for Handling Spatial-Temporal Data_. doi:10.5281/zenodo.1158580 , R package version 6.15.2.9001, . A BibTeX entry for LaTeX users is @@ -65,7 +65,7 @@ A BibTeX entry for LaTeX users is title = {magclass: Data Class and Tools for Handling Spatial-Temporal Data}, author = {Jan Philipp Dietrich and Benjamin Leon Bodirsky and Markus Bonsch and Florian Humpenoeder and Stephen Bi and Kristine Karstens and Debbora Leip and Pascal Sauer}, year = {2024}, - note = {R package version 6.15.2}, + note = {R package version 6.15.2.9001}, doi = {10.5281/zenodo.1158580}, url = {https://github.com/pik-piam/magclass}, }