Skip to content

Commit

Permalink
Merge pull request #173 from 0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q/dev/ver…
Browse files Browse the repository at this point in the history
…bose_mbind

Verbose mbind() Error Message on Multiple Differing Dimensions

close pik-piam/remind2#604
  • Loading branch information
0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q authored May 28, 2024
2 parents eb69ba3 + 9606026 commit 58f500a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]",
comment = c(affiliation = "Potsdam Institute for Climate Impact Research", ORCID = "0000-0002-4309-6431"), role = c("aut", "cre")),
Expand Down
46 changes: 43 additions & 3 deletions R/mbind.R
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -56,7 +56,7 @@ In case of questions / problems please contact Jan Philipp Dietrich <dietrich@pi

To cite package **magclass** in publications use:

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 (URL: https://doi.org/10.5281/zenodo.1158580), R package version 6.15.2, <URL: https://github.com/pik-piam/magclass>.
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 <https://doi.org/10.5281/zenodo.1158580>, R package version 6.15.2.9001, <https://github.com/pik-piam/magclass>.

A BibTeX entry for LaTeX users is

Expand All @@ -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},
}
Expand Down

0 comments on commit 58f500a

Please sign in to comment.