Skip to content

Commit

Permalink
Merge pull request #180 from whitehacker/master
Browse files Browse the repository at this point in the history
Add warning for unset 'where' argument in toolGetMapping function
  • Loading branch information
pfuehrlich-pik authored Sep 28, 2023
2 parents 826d4b1 + ff36152 commit 4d7fcc6
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '7159110'
ValidationKey: '7183116'
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: 'madrat: May All Data be Reproducible and Transparent (MADRaT) *'
version: 3.6.5
date-released: '2023-09-14'
version: 3.6.6
date-released: '2023-09-26'
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
4 changes: 2 additions & 2 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.5
Date: 2023-09-14
Version: 3.6.6
Date: 2023-09-26
Authors@R: c(
person("Jan Philipp", "Dietrich", , "[email protected]", role = c("aut", "cre")),
person("Lavinia", "Baumstark", , "[email protected]", role = "aut"),
Expand Down
9 changes: 8 additions & 1 deletion R/toolGetMapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,15 @@ toolGetMapping <- function(name, type = NULL, where = NULL,
error.missing = TRUE, # nolint
returnPathOnly = FALSE, activecalc = NULL) {

if (isWrapperActive("wrapperChecks")) {
for (w in c("downloadSource", "readSource", "calcOutput", "retrieveData")) {
if (isWrapperActive(w) && is.null(where)) {
warning("argument 'where' should be set when calling toolGetMapping from within a madrat function.")
break
}
}
}
setWrapperInactive("wrapperChecks")

fname <- .searchName(name = name, type = type, where = where, activecalc = activecalc)

if (error.missing && !file.exists(as.character(fname))) stop('Mapping "', name, '" not found!')
Expand Down
6 changes: 3 additions & 3 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.5**
R package **madrat**, version **3.6.6**

[![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,7 +55,7 @@ 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 <https://doi.org/10.5281/zenodo.1115490>, R package version 3.6.5, <https://github.com/pik-piam/madrat>.
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 <https://doi.org/10.5281/zenodo.1115490>, R package version 3.6.6, <https://github.com/pik-piam/madrat>.

A BibTeX entry for LaTeX users is

Expand All @@ -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 Führlich},
year = {2023},
note = {R package version 3.6.5},
note = {R package version 3.6.6},
doi = {10.5281/zenodo.1115490},
url = {https://github.com/pik-piam/madrat},
}
Expand Down
40 changes: 21 additions & 19 deletions tests/testthat/test-calcOutput.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ test_that("Calculation for tau example data set works", {
require(magclass)
localConfig(ignorecache = FALSE, forcecache = FALSE, verbosity = 2)
expectedResult <- new("magpie",
.Data = structure(c(0.99, 0.83, 0.68, 1.47, 0.9, 0.64, 0.8, 0.97, 1.17, 0.89, 1.27, 1.25),
.Dim = c(12L, 1L, 1L),
.Dimnames = list(region = c("LAM", "OAS", "SSA", "EUR", "NEU", "MEA",
"REF", "CAZ", "CHA", "IND", "JPN", "USA"),
year = NULL, data = NULL)))
.Data = structure(c(0.99, 0.83, 0.68, 1.47, 0.9, 0.64, 0.8, 0.97, 1.17, 0.89, 1.27, 1.25),
.Dim = c(12L, 1L, 1L),
.Dimnames = list(region = c("LAM", "OAS", "SSA", "EUR", "NEU", "MEA",
"REF", "CAZ", "CHA", "IND", "JPN", "USA"),
year = NULL, data = NULL)))
x <- calcOutput("TauTotal", source = "historical", years = 1995, round = 2, supplementary = TRUE)
expect_true(is.list(x))
expect_equivalent(x$x, expectedResult)
Expand All @@ -147,11 +147,11 @@ test_that("Standard workflow works", {
}
fullTEST2 <- function(rev = 0, dev = "") {
expectedOutput <- new("magpie",
.Data = structure(c(540, 490, 510, 331, 160, 210, 120, 50, 40, 10, 10, 10),
.Dim = c(12L, 1L, 1L),
.Dimnames = list(fake = c("LAM", "OAS", "SSA", "EUR", "NEU", "MEA", "REF",
"CAZ", "CHA", "IND", "JPN", "USA"),
year = NULL, data = NULL)))
.Data = structure(c(540, 490, 510, 331, 160, 210, 120, 50, 40, 10, 10, 10),
.Dim = c(12L, 1L, 1L),
.Dimnames = list(fake = c("LAM", "OAS", "SSA", "EUR", "NEU", "MEA", "REF",
"CAZ", "CHA", "IND", "JPN", "USA"),
year = NULL, data = NULL)))

expect_warning(co <- capture.output(a <- calcOutput("Test2", file = "test.mz")),
'Missing description for data set "Test2"')
Expand Down Expand Up @@ -268,15 +268,17 @@ test_that("Aggregation works", {
"JPN", "USA"),
year = NULL, data = NULL)))
glo <- new("magpie", .Data = structure(249, .Dim = c(1L, 1L, 1L),
.Dimnames = list(region = "GLO", year = NULL, data = NULL)))
.Dimnames = list(region = "GLO", year = NULL, data = NULL)))

country2 <- new("magpie", .Data = structure(rep(8, 249), .Dim = c(249L, 1L, 1L), .Dimnames = list(
country = unname(getISOlist()), year = NULL, data = NULL)))
country2 <- new("magpie", .Data = structure(rep(8, 249), .Dim = c(249L, 1L, 1L),
.Dimnames = list(country = unname(getISOlist()),
year = NULL, data = NULL)))

reg2 <- new("magpie", .Data = structure(c(432, 392, 408, 272, 128, 168,
96, 40, 32, 8, 8, 8), .Dim = c(12L, 1L, 1L), .Dimnames = list(
region = c("LAM", "OAS", "SSA", "EUR", "NEU", "MEA", "REF",
"CAZ", "CHA", "IND", "JPN", "USA"), year = NULL, data = NULL)))
96, 40, 32, 8, 8, 8), .Dim = c(12L, 1L, 1L),
.Dimnames = list(region = c("LAM", "OAS", "SSA", "EUR", "NEU", "MEA",
"REF", "CAZ", "CHA", "IND", "JPN", "USA"),
year = NULL, data = NULL)))
glo2 <- new("magpie", .Data = structure(1992, .Dim = c(1L, 1L, 1L),
.Dimnames = list(global = "GLO", year = NULL, data = NULL)))

Expand Down Expand Up @@ -308,8 +310,8 @@ test_that("Aggregation works", {
# set verbosity to a level that will produce the expected NOTE
localConfig(verbosity = 1)
expect_message(a <- nc(calcOutput("AggregationTest", aggregate = "glo")),
paste0("Ignoring column\\(s\\) X, region, global from .* as the column\\(s\\) ",
"already exist in another mapping\\."))
paste0("Ignoring column\\(s\\) X, region, global from .* as the column\\(s\\) ",
"already exist in another mapping\\."))
expect_identical(a, glo)
})
})
Expand Down Expand Up @@ -348,7 +350,7 @@ test_that("1on1 country mappings do not alter the data", {

test_that("Bilateral aggregation works", {
calcBilateral <- function() {
map <- toolGetMapping("regionmappingH12.csv")
map <- toolGetMapping("regionmappingH12.csv", where = "madrat")
tmp <- expand.grid(map[[2]], map[[2]], stringsAsFactors = FALSE)
x <- new.magpie(paste0(tmp[[1]], ".", tmp[[2]]))
x[, , ] <- rep(seq_len(nrow(map)), nrow(map))
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-toolGetMapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@ test_that("toolGetMapping works", {
writeLines("abc", paste0(getConfig("mappingfolder"), "/test.xyz"))
expect_error(toolGetMapping("test.rda", where = "mappingfolder"), "did not contain a object")
expect_error(toolGetMapping("test.xyz"), "Unsupported filetype")

readTest <- function() {
toolGetMapping("regionmappingH12.csv", type = "regional")
return(as.magpie(1))
}
globalassign("readTest")
expect_warning(readSource("Test"),
"argument 'where' should be set when calling toolGetMapping from within a madrat function.")
})

0 comments on commit 4d7fcc6

Please sign in to comment.