Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tests #231

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '63234546'
ValidationKey: '63330315'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand All @@ -7,3 +7,4 @@ AutocreateReadme: yes
allowLinterWarnings: no
enforceVersionUpdate: no
skipCoverage: no
AutocreateCITATION: yes
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exclude: '^tests/testthat/_snaps/.*$'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c # frozen: v4.6.0
rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0
hooks:
- id: check-case-conflict
- id: check-json
Expand All @@ -15,7 +15,7 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/lorenzwalthert/precommit
rev: bae853d82da476eee0e0a57960ee6b741a3b3fb7 # frozen: v0.4.3
rev: 3b70240796cdccbe1474b0176560281aaded97e6 # frozen: v0.4.3.9003
hooks:
- id: parsable-R
- id: deps-in-desc
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.15.4
date-released: '2024-11-22'
version: 3.15.5
date-released: '2024-12-16'
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.15.4
Date: 2024-11-22
Version: 3.15.5
Date: 2024-12-16
Authors@R: c(
person("Jan Philipp", "Dietrich", , "[email protected]", role = c("aut", "cre"),
comment = c(affiliation = "Potsdam Institute for Climate Impact Research", ORCID = "0000-0002-4309-6431")),
Expand Down
95 changes: 50 additions & 45 deletions R/prepFunctionName.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#' prepFunctionName
#'
#'
#' Function to prepare a function call for a given type and prefix
#'
#'
#'
#' @aliases prepFunctionName
#' @param type name of calculation/source
#' @param prefix Type of calculations. Available options are "download" (source download),
#' @param prefix Type of calculations. Available options are "download" (source download),
#' "read" (source read), "correct" (source corrections), "convert" (source conversion to ISO countries),
#' "calc" (further calculations), and "full" (collections of calculations)
#' @param ignore vector of arguments which should be ignored (not be part of the function call)
Expand All @@ -14,72 +13,78 @@
#' @author Jan Philipp Dietrich
#' @seealso \code{\link{readSource}}, \code{\link{setConfig}}
#' @examples
#'
#' print(madrat:::prepFunctionName("Tau","read"))
#' print(madrat:::prepFunctionName("TauTotal","calc"))
#' print(madrat:::prepFunctionName("EXAMPLE","full"))
#'
#' print(madrat:::prepFunctionName("Tau", "read"))
#' print(madrat:::prepFunctionName("TauTotal", "calc"))
#' print(madrat:::prepFunctionName("EXAMPLE", "full"))
#' @importFrom utils tail

prepFunctionName <- function(type, prefix="calc", ignore=NULL, error_on_missing=TRUE) {
prepFunctionName <- function(type, prefix = "calc", ignore = NULL,
error_on_missing = TRUE) { # nolint: object_name_linter.
getCalc <- getCalculations(prefix = prefix)
if(!(type %in% getCalc$type)) {
if(error_on_missing) {
stop("Type \"",type, "\" is not a valid output type. Check getCalculations(\"",prefix,"\") for available types!")
if (!(type %in% getCalc$type)) {
if (error_on_missing) {
stop("Type \"", type, "\" is not a valid output type. Check getCalculations(\"",
prefix, "\") for available types!")
} else {
return(NULL)
}
}
# creates functionname and checks that all arguments
# expected by the function are actually beeing provided
name <- getCalc$call[getCalc$type==type]
package <- getCalc$package[getCalc$type==type]
if(length(name)>1) {
name <- as.character(tail(name,1))
package <- as.character(tail(package,1))
warning("More than one function found for type \"",type,"\" and prefix \"",prefix,"\". Use last occurrence (package \"",package,"\")")
if(package==".GlobalEnv" & type %in% c("TauTotal","Tau")) {
stop("Cannot substitute package internal function for type \"",type,"\" and prefix \"",prefix,"\" with function in global environment. Please use other function name instead!")
}
name <- getCalc$call[getCalc$type == type]
package <- getCalc$package[getCalc$type == type]
if (length(name) > 1) {
name <- as.character(tail(name, 1))
package <- as.character(tail(package, 1))
warning("More than one function found for type \"", type, "\" and prefix \"", prefix,
"\". Use last occurrence (package \"", package, "\")")
if (package == ".GlobalEnv" && type %in% c("TauTotal", "Tau")) {
stop("Cannot substitute package internal function for type \"", type, "\" and prefix \"",
prefix, "\" with function in global environment. Please use other function name instead!")
}
}

# extract arguments which agree between the given function and its corresponding wrapper function
# (because they have to be mentioned specifically in the function call)
wrapper <- list(calc = "calcOutput",

wrapper <- list(calc = "calcOutput",
download = "downloadSource",
read = "readSource",
read = "readSource",
correct = "readSource",
convert = "readSource",
full = "retrieveData")
if(prefix %in% c("convert", "correct")) {

if (prefix %in% c("convert", "correct")) {
add <- "x"
} else{
} else {
add <- NULL
}

fformals <- names(formals(eval(parse(text = name))))
wformals <- c(add,names(formals(as.character(wrapper[prefix]))))
wformals <- c(add, names(formals(as.character(wrapper[prefix]))))
formals <- intersect(wformals, fformals)
fcomplete <- all(fformals %in% formals)
formals <- setdiff(formals,"...")
if(!fcomplete & !("..." %in% wformals)) {
formals <- setdiff(formals, "...")

if (!fcomplete && !("..." %in% wformals)) {
warning("Some arguments of function \"", name, "\" cannot be adressed by the wrapper (\"",
paste0(fformals[!(fformals %in% formals)], collapse = "\", \""),"\")!")
paste0(fformals[!(fformals %in% formals)], collapse = "\", \""), "\")!")
}

formals <- setdiff(formals,ignore)
args <- paste(formals,formals,sep="=")
if("..." %in% wformals & !fcomplete) args <- c(args,"...")
out <- paste0(name,'(',paste(args,collapse=", "),')')

attr(out,"formals") <- formals
attr(out,"package") <- package
if(package==".GlobalEnv") {
attr(out,"pkgcomment") <- ".GlobalEnv"

formals <- setdiff(formals, ignore)
args <- paste(formals, formals, sep = "=")
if ("..." %in% wformals && !fcomplete) {
args <- c(args, "...")
}
out <- paste0(name, "(", paste(args, collapse = ", "), ")")

attr(out, "formals") <- formals
attr(out, "package") <- package
if (package == ".GlobalEnv") {
attr(out, "pkgcomment") <- ".GlobalEnv"
} else {
attr(out,"pkgcomment") <- paste(package, unname(getNamespaceVersion(package)))
attr(out, "pkgcomment") <- paste(package, unname(getNamespaceVersion(package)))
}
return(out)
}
2 changes: 1 addition & 1 deletion R/putMadratMessage.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ putMadratMessage <- function(name, value, fname = -1, add = FALSE) {
for (n in name) {
madratMessage[[name]][[fname]] <- if (add) c(madratMessage[[name]][[fname]], value) else value
}
options(madratMessage = madratMessage) # nolint: undesirable_function_linter
options(madratMessage = madratMessage) # nolint: undesirable_function_linter.
}
}
2 changes: 1 addition & 1 deletion R/readSource.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#' }
#'
#' @export
readSource <- function(type, subtype = NULL, subset = NULL, # nolint: cyclocomp_linter
readSource <- function(type, subtype = NULL, subset = NULL, # nolint: cyclocomp_linter.
convert = TRUE, supplementary = FALSE) {
argumentValues <- as.list(environment()) # capture arguments for logging

Expand Down
2 changes: 1 addition & 1 deletion R/resetMadratMessages.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ resetMadratMessages <- function(name = NULL, fname = NULL) {
madratMessage[[name]][[fname]] <- NULL
}
if (length(madratMessage) == 0) madratMessage <- NULL
options(madratMessage = madratMessage) # nolint: undesirable_function_linter
options(madratMessage = madratMessage) # nolint: undesirable_function_linter.
}
2 changes: 1 addition & 1 deletion R/robustOrder.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' @seealso \code{\link[base]{order}}
#' @author Pascal Sauer
robustOrder <- function(...,
na.last = TRUE, # nolint: object_name_linter
na.last = TRUE, # nolint: object_name_linter.
decreasing = FALSE, method = "radix") {
args <- list(...)
if (any(lapply(args, length) == 0)) {
Expand Down
2 changes: 1 addition & 1 deletion R/visualizeDependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' @export


visualizeDependencies <- function(..., direction = "both", order = 2, filter = NULL, # nolint: cyclocomp_linter
visualizeDependencies <- function(..., direction = "both", order = 2, filter = NULL, # nolint: cyclocomp_linter.
packages = getConfig("packages"), filename = NULL) {
# check for required packages
if (!requireNamespace("graphics", quietly = TRUE)) {
Expand Down
13 changes: 7 additions & 6 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.15.4**
R package **madrat**, version **3.15.5**

[![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,17 +55,18 @@ 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, Sauer P (2024). _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.15.4, <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 (2024). "madrat: May All Data be Reproducible and Transparent (MADRaT) *." doi:10.5281/zenodo.1115490 <https://doi.org/10.5281/zenodo.1115490>, Version: 3.15.5, <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)},
@Misc{,
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},
doi = {10.5281/zenodo.1115490},
date = {2024-12-16},
year = {2024},
note = {R package version 3.15.4},
url = {https://github.com/pik-piam/madrat},
doi = {10.5281/zenodo.1115490},
note = {Version: 3.15.5},
}
```
8 changes: 4 additions & 4 deletions man/prepFunctionName.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/test-toolCountryFill.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ test_that("toolCountryFill works as expected", {
x <- new.magpie("DEU", 1994, "bla", 0)
expect_message(y <- toolCountryFill(x, 99), "toolCountryFill set missing values for IMPORTANT")
expect_equal(dim(y)[1], 249)
expect_true(y["DEU", , ] == 0)
expect_true(all(y["DEU", , ] == 0))
expect_true(all(y["DEU", , , invert = TRUE] == 99))

x2 <- new.magpie(c("DEU", "XYZ"), 1994, "bla", 0)
Expand All @@ -19,9 +19,9 @@ test_that("toolCountryFill works as expected", {

x3 <- new.magpie(c("DEU", "FRA"), 1994, "bla", 0)
x3["FRA", , ] <- 42
expect_true(toolCountryFill(x3, 99, FRA = "DEU")["FRA", , ] == 42)
expect_true(all(toolCountryFill(x3, 99, FRA = "DEU")["FRA", , ] == 42))
expect_message(y5 <- toolCountryFill(x3, 99, FRA = "DEU", overwrite = TRUE), "data overwritten")
expect_true(y5["FRA", , ] == 0)
expect_true(all(y5["FRA", , ] == 0))

empty <- new.magpie(NULL, NULL, c("bla"))
expect_silent(y6 <- toolCountryFill(empty, verbosity = 3))
Expand Down
Loading