Skip to content

Commit

Permalink
Merge pull request #185 from pfuehrlich-pik/master
Browse files Browse the repository at this point in the history
fix codelabels in pucAggregate
  • Loading branch information
pfuehrlich-pik authored Oct 13, 2023
2 parents 9de5e21 + c08de15 commit f4f7edb
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '7208614'
ValidationKey: '7228624'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
8 changes: 4 additions & 4 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: 'madrat: May All Data be Reproducible and Transparent (MADRaT) *'
version: 3.6.7
date-released: '2023-10-12'
version: 3.6.8
date-released: '2023-10-13'
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
Expand Down Expand Up @@ -38,9 +38,9 @@ authors:
- family-names: Klein
given-names: David
email: [email protected]
- family-names: Führlich
- family-names: Sauer
given-names: Pascal
email: pascal.fuehrlich@pik-potsdam.de
email: pascal.sauer@pik-potsdam.de
license: BSD-2-Clause
repository-code: https://github.com/pik-piam/madrat
doi: 10.5281/zenodo.1115490
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: madrat
Title: May All Data be Reproducible and Transparent (MADRaT) *
Version: 3.6.7
Date: 2023-10-12
Version: 3.6.8
Date: 2023-10-13
Authors@R: c(
person("Jan Philipp", "Dietrich", , "[email protected]", role = c("aut", "cre")),
person("Lavinia", "Baumstark", , "[email protected]", role = "aut"),
Expand All @@ -13,7 +13,7 @@ Authors@R: c(
person("Debbora", "Leip", , "[email protected]", role = "aut"),
person("Ulrich", "Kreidenweis", , "[email protected]", role = "aut"),
person("David", "Klein", , "[email protected]", role = "aut"),
person("Pascal", "Führlich", , "pascal.fuehrlich@pik-potsdam.de", role = "aut")
person("Pascal", "Sauer", , "pascal.sauer@pik-potsdam.de", role = "aut")
)
Description: Provides a framework which should improve reproducibility and
transparency in data processing. It provides functionality such as
Expand Down
2 changes: 1 addition & 1 deletion R/compareMadratOutputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#' compareMadratOutputs("madrat", "readTau", c("paper", "historical"))
#' }
#'
#' @author Pascal Führlich
#' @author Pascal Sauer
#'
#' @importFrom digest digest
#' @importFrom magclass where
Expand Down
2 changes: 1 addition & 1 deletion R/downloadSource.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#' }
#' Besides the names above (user-provided and automatically derived) it is possible to add custom metadata entries by
#' extending the return list with additional, named entries.
#' @author Jan Philipp Dietrich, David Klein, Pascal Führlich
#' @author Jan Philipp Dietrich, David Klein, Pascal Sauer
#' @examples
#' \dontrun{
#' a <- downloadSource("Tau", subtype = "historical")
Expand Down
85 changes: 42 additions & 43 deletions R/fingerprint.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#' @param ... Additional arguments for \code{\link{getMadratGraph}} in case
#' that no graph is provided (otherwise ignored)
#' @return A fingerprint (hash) of all provided sources, or "fingerprintError"
#' @author Jan Philipp Dietrich, Pascal Führlich
#' @author Jan Philipp Dietrich, Pascal Sauer
#' @seealso \code{\link{readSource}}
#' @examples
#' madrat:::fingerprint("toolGetMapping", package = "madrat")
Expand All @@ -36,52 +36,51 @@
fingerprint <- function(name, details = FALSE, graph = NULL, ...) {
dependencies <- getDependencies(name, direction = "in", self = TRUE, graph = graph, ...)
result <- tryCatch({
fingerprintFunctions <- dependencies$hash[robustOrder(dependencies$call)]
names(fingerprintFunctions) <- dependencies$call[robustOrder(dependencies$call)]
fingerprintFunctions <- dependencies$hash[robustOrder(dependencies$call)]
names(fingerprintFunctions) <- dependencies$call[robustOrder(dependencies$call)]

# handle special requests via flags
.tmp <- function(x) {
return(robustSort(sub(":+", ":::", x)))
}
ignore <- .tmp(attr(dependencies, "flags")$ignore)
monitor <- .tmp(attr(dependencies, "flags")$monitor)
# if conflicting information is giving (monitor and ignore at the same time,
# prioritize monitor request)
ignore <- setdiff(ignore, monitor)
# add calls from the monitor list which are not already monitored
fingerprintMonitored <- fingerprintCall(setdiff(monitor, names(fingerprintFunctions)))
# ignore functions mentioned in the ignore list
fingerprintFunctions <- fingerprintFunctions[setdiff(names(fingerprintFunctions), ignore)]
sources <- substring(dependencies$func[dependencies$type == "read"], 5)
if (length(sources) > 0) {
sources <- paste0(getConfig("sourcefolder"), "/", robustSort(sources))
}
fingerprintSources <- fingerprintFiles(sources)
fingerprintMappings <- fingerprintFiles(attr(dependencies, "mappings"))
fingerprint <- c(fingerprintFunctions, fingerprintSources, fingerprintMappings, fingerprintMonitored)
fingerprint <- fingerprint[robustOrder(basename(names(fingerprint)))]
# handle special requests via flags
.tmp <- function(x) {
return(robustSort(sub(":+", ":::", x)))
}
ignore <- .tmp(attr(dependencies, "flags")$ignore)
monitor <- .tmp(attr(dependencies, "flags")$monitor)
# if conflicting information is giving (monitor and ignore at the same time,
# prioritize monitor request)
ignore <- setdiff(ignore, monitor)
# add calls from the monitor list which are not already monitored
fingerprintMonitored <- fingerprintCall(setdiff(monitor, names(fingerprintFunctions)))
# ignore functions mentioned in the ignore list
fingerprintFunctions <- fingerprintFunctions[setdiff(names(fingerprintFunctions), ignore)]
sources <- substring(dependencies$func[dependencies$type == "read"], 5)
if (length(sources) > 0) {
sources <- paste0(getConfig("sourcefolder"), "/", robustSort(sources))
}
fingerprintSources <- fingerprintFiles(sources)
fingerprintMappings <- fingerprintFiles(attr(dependencies, "mappings"))
fingerprint <- c(fingerprintFunctions, fingerprintSources, fingerprintMappings, fingerprintMonitored)
fingerprint <- fingerprint[robustOrder(basename(names(fingerprint)))]

# Cache files became incompatible when readSource was allowed to return non-magpie objects.
# Referring to madrat versions before this change as "old" and after this change as "new" here:
# Hashing the string "v2" leads to completely new hashes, and thus cache files with different names.
# Old madrat versions will never read/write these new cache files, and new madrat versions will never
# read/write cache files created with an old madrat version.
out <- digest(list("v2", unname(fingerprint)), algo = getConfig("hash"))
# Cache files became incompatible when readSource was allowed to return non-magpie objects.
# Referring to madrat versions before this change as "old" and after this change as "new" here:
# Hashing the string "v2" leads to completely new hashes, and thus cache files with different names.
# Old madrat versions will never read/write these new cache files, and new madrat versions will never
# read/write cache files created with an old madrat version.
out <- digest(list("v2", unname(fingerprint)), algo = getConfig("hash"))

if (details) {
attr(out, "details") <- fingerprint
vcat(3, "hash components (", out, "):", show_prefix = FALSE)
for (n in names(fingerprint)) {
vcat(3, " ", fingerprint[n], " | ", basename(n), " | ", n, show_prefix = FALSE)
}
if (details) {
attr(out, "details") <- fingerprint
vcat(3, "hash components (", out, "):", show_prefix = FALSE)
for (n in names(fingerprint)) {
vcat(3, " ", fingerprint[n], " | ", basename(n), " | ", n, show_prefix = FALSE)
}
out
},
error = function(error) {
vcat(2, paste(" - Fingerprinting failed:", error), show_prefix = FALSE)
return("fingerprintError")
}
)
out
},
error = function(error) {
vcat(2, paste(" - Fingerprinting failed:", error), show_prefix = FALSE)
return("fingerprintError")
})
attr(result, "call") <- dependencies$call[dependencies$func == name]
return(result)
}
Expand Down Expand Up @@ -135,7 +134,7 @@ fingerprintFiles <- function(paths) {
# return file name for fileHash cache if the given path belongs to a source folder,
# otherwise return NULL
if (dir.exists(getConfig("sourcefolder")) &&
startsWith(normalizePath(path), normalizePath(getConfig("sourcefolder")))) {
startsWith(normalizePath(path), normalizePath(getConfig("sourcefolder")))) {
return(paste0(getConfig("cachefolder"), "/fileHashCache", basename(path), ".rds"))
} else {
return(NULL)
Expand Down
10 changes: 6 additions & 4 deletions R/pucAggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ pucAggregate <- function(puc, regionmapping = getConfig("regionmapping"), ..., r
puc <- normalizePath(puc)
if (file.exists(regionmapping)) regionmapping <- normalizePath(regionmapping)

.aggregatePuc <- function(regionmapping, cfg, madratCfg, nestinglevel) {
.aggregatePuc <- function(regionmapping, cfg, madratCfg, madratCodelabels, nestinglevel) {
# need to use `::` because this is run in another R session
if (file.exists("puc/renv.lock")) {
renv::init()
renv::restore(lockfile = "puc/renv.lock", prompt = FALSE)
}
withr::local_options(madrat_cfg = madratCfg, gdt_nestinglevel = nestinglevel)
withr::local_options(madrat_cfg = madratCfg,
madrat_codelabels = madratCodelabels,
gdt_nestinglevel = nestinglevel)
madrat::localConfig(packages = "madrat", regionmapping = regionmapping,
forcecache = TRUE, .verbose = FALSE)
if (!is.null(cfg$package)) withr::local_package(cfg$package)
Expand All @@ -67,6 +69,7 @@ pucAggregate <- function(puc, regionmapping = getConfig("regionmapping"), ..., r
if (isTRUE(renv)) {
out <- capture.output(r(.aggregatePuc, list(regionmapping = regionmapping, cfg = cfg,
madratCfg = getOption("madrat_cfg"),
madratCodelabels = getOption("madrat_codelabels"),
nestinglevel = getOption("gdt_nestinglevel")),
spinner = FALSE, show = TRUE))
message(paste(out, "\n"))
Expand All @@ -75,8 +78,7 @@ pucAggregate <- function(puc, regionmapping = getConfig("regionmapping"), ..., r
if (!is.null(cfg$package) && !cfg$package %in% .packages()) {
withr::local_package(cfg$package)
}
localConfig(regionmapping = regionmapping, forcecache = TRUE,
.verbose = FALSE)
localConfig(regionmapping = regionmapping, forcecache = TRUE, .verbose = FALSE)
do.call(retrieveData, c(cfg$args, list(renv = FALSE)))
}
}, tmpdir = madTempDir())
Expand Down
2 changes: 1 addition & 1 deletion R/readSource.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#' the data and metadata is returned instead. The temporal and data dimensionality
#' should match the source data. The spatial dimension should either match the source data or,
#' if the convert argument is set to TRUE, should be on ISO code country level.
#' @author Jan Philipp Dietrich, Anastasis Giannousakis, Lavinia Baumstark, Pascal Führlich
#' @author Jan Philipp Dietrich, Anastasis Giannousakis, Lavinia Baumstark, Pascal Sauer
#' @seealso \code{\link{setConfig}}, \code{\link{downloadSource}}, \code{\link{readTau}}
#' #' @note The underlying read-functions can return a magpie object or a list of information
#' (preferred) back to \code{readSource}. In list format the object should have the following
Expand Down
2 changes: 1 addition & 1 deletion R/robustOrder.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' @param method Default is "radix", which is locale independent. The alternatives "auto" and "shell" should not be used
#' in madrat because they are locale dependent.
#' @seealso \code{\link[base]{order}}
#' @author Pascal Führlich
#' @author Pascal Sauer
robustOrder <- function(...,
na.last = TRUE, # nolint: object_name_linter
decreasing = FALSE, method = "radix") {
Expand Down
2 changes: 1 addition & 1 deletion R/toolstartmessage.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' next vcat executions. Currently this setting can have 4 states: NULL (nothing will be changed), 0 (reset
#' hierarchies), "+" (increase hierarchy level by 1) and "-" (decrease hierarchy level by 1).
#' @return A list containing diagnostic information required by \code{\link{toolendmessage}}.
#' @author Jan Philipp Dietrich, Pascal Führlich
#' @author Jan Philipp Dietrich, Pascal Sauer
#' @seealso \code{\link{toolendmessage}}, \code{\link{vcat}}
#' @importFrom utils str
#' @examples
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# May All Data be Reproducible and Transparent (MADRaT) *

R package **madrat**, version **3.6.7**
R package **madrat**, version **3.6.8**

[![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)

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

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

Dietrich J, Baumstark L, Wirth S, Giannousakis A, Rodrigues R, Bodirsky B, Leip D, Kreidenweis U, Klein D, Führlich P (2023). _madrat: May All Data be Reproducible and Transparent (MADRaT)_. doi: 10.5281/zenodo.1115490 (URL: https://doi.org/10.5281/zenodo.1115490), R package version 3.6.7, <URL: https://github.com/pik-piam/madrat>.
Dietrich J, Baumstark L, Wirth S, Giannousakis A, Rodrigues R, Bodirsky B, Leip D, Kreidenweis U, Klein D, Sauer P (2023). _madrat: May All Data be Reproducible and Transparent (MADRaT)_. doi:10.5281/zenodo.1115490 <https://doi.org/10.5281/zenodo.1115490>, R package version 3.6.8, <https://github.com/pik-piam/madrat>.

A BibTeX entry for LaTeX users is

```latex
@Manual{,
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 Führlich},
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 = {2023},
note = {R package version 3.6.7},
note = {R package version 3.6.8},
doi = {10.5281/zenodo.1115490},
url = {https://github.com/pik-piam/madrat},
}
Expand Down
2 changes: 1 addition & 1 deletion man/compareMadratOutputs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/downloadSource.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/fingerprint.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/readSource.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/robustOrder.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/toolstartmessage.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f4f7edb

Please sign in to comment.