From ccba0ad67e02e3df9ad739fd5e2fb465fdcb54df Mon Sep 17 00:00:00 2001 From: fbenke-pik Date: Thu, 25 Jan 2024 11:17:31 +0100 Subject: [PATCH] make filtering in loadModeltest more robust --- .buildlibrary | 2 +- CITATION.cff | 4 ++-- DESCRIPTION | 6 +++--- R/loadModeltest.R | 42 +++++++++++++++++++++++++----------------- README.md | 6 +++--- man/loadModeltest.Rd | 4 ++-- 6 files changed, 36 insertions(+), 28 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index 1aa3d824..198c5ad7 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '223107200' +ValidationKey: '223160847' 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 c00231c8..a180adf0 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: 'remind2: The REMIND R package (2nd generation)' -version: 1.130.0 -date-released: '2024-01-22' +version: 1.130.1 +date-released: '2024-01-25' abstract: Contains the REMIND-specific routines for data and model output manipulation. authors: - family-names: Rodrigues diff --git a/DESCRIPTION b/DESCRIPTION index 382d5071..b9b0fee7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: remind2 Title: The REMIND R package (2nd generation) -Version: 1.130.0 -Date: 2024-01-22 +Version: 1.130.1 +Date: 2024-01-25 Authors@R: c( person("Renato", "Rodrigues", , "renato.rodrigues@pik-potsdam.de", role = c("aut", "cre")), person("Lavinia", "Baumstark", role = "aut"), @@ -89,6 +89,6 @@ Suggests: VignetteBuilder: knitr Encoding: UTF-8 -RoxygenNote: 7.3.0 +RoxygenNote: 7.3.1 Config/testthat/parallel: true Config/testthat/edition: 3 diff --git a/R/loadModeltest.R b/R/loadModeltest.R index 374c22ad..fa82033a 100644 --- a/R/loadModeltest.R +++ b/R/loadModeltest.R @@ -1,9 +1,9 @@ #' @importFrom utils globalVariables -globalVariables(".") +globalVariables(".") # nolint getProjectPath <- function(project = "remind") { - possibleProjectLocations <- file.path(c("//clusterfs.pik-potsdam.de", "/p/projects"), project) + possibleProjectLocations <- file.path(c("//clusterfs.pik-potsdam.de", "p", "projects"), project) sel <- which(file.exists(possibleProjectLocations))[1] if (is.na(sel)) stop("Cannot determine a path to projects on the cluster.") possibleProjectLocations[sel] @@ -20,7 +20,8 @@ getNewsestModeltests <- function(namePattern, requireMif) { grep( x = ., pattern = "^[a-zA-Z0-9-]+_\\d{4}-\\d{2}-\\d{2}_\\d{2}\\.\\d{2}\\.\\d{2}$", - value = TRUE) + value = TRUE + ) allRuns <- allRunNames %>% strsplit("_", fixed = TRUE) %>% @@ -31,6 +32,8 @@ getNewsestModeltests <- function(namePattern, requireMif) { bind_cols(runName = allRunNames) %>% mutate(date = as.Date(.data$date)) %>% mutate(path = file.path(.env$modeltestOutPath, .data$runName)) %>% + filter(date >= max(.data$date) - 180) %>% # limit to half a year + filter(file.exists(file.path(.data$path, "config.Rdata"))) %>% mutate(mifScen = getMifScenPath(.data$path)) selectedRuns <- allRuns %>% @@ -57,11 +60,11 @@ getNewsestModeltests <- function(namePattern, requireMif) { #' } #' @export loadCs2Data <- function( - mifScen, - mifHist, - cfgScen = NULL, - cfgDefault = NULL, - envir = globalenv() + mifScen, + mifHist, + cfgScen = NULL, + cfgDefault = NULL, + envir = globalenv() ) { folder <- tempdir() @@ -76,7 +79,8 @@ loadCs2Data <- function( outputFile = outputFile, sections = NULL, envir = envir, - quiet = TRUE) + quiet = TRUE + ) file.remove(file.path(folder, paste0(outputFile, ".pdf"))) return(invisible(NULL)) } @@ -112,15 +116,15 @@ cs2InputPaths <- function(outputDirs) { #' ssp1 <- new.env() #' ssp2eu <- new.env() #' loadModeltest(ssp1, "^SSP1-AMT-") -#' loadModeltest(ssp2eu, "^SSP2EU-AMT-") +#' loadModeltest(ssp2eu, "^SSP2EU-.*-AMT$") #' ssp1$data #' ssp2eu$data #' } #' @export loadModeltest <- function( - envir = globalenv(), - namePattern = "^SSP2EU-AMT-", - folder = tempdir() + envir = globalenv(), + namePattern = "^SSP2EU-.*-AMT$", + folder = tempdir() ) { stopifnot(is.environment(envir)) @@ -143,7 +147,8 @@ loadModeltest <- function( mifScen = file.path(folder, paste0(modeltests$name, ".mif")), mifHist = file.path(folder, "historical.mif"), cfgScen = file.path(folder, paste0(modeltests$name, ".Rdata")), - cfgDefault = file.path(folder, "default.cfg")) + cfgDefault = file.path(folder, "default.cfg") + ) copyFile <- function(from, to) { cat("Copying\n ", paste(from, collapse = "\n "), @@ -155,7 +160,8 @@ loadModeltest <- function( warning( "failed copying following files\n", paste(from[!success], collapse = "\n"), - immediate. = TRUE) + immediate. = TRUE + ) } copyFile(path$mifScen, tmpPath$mifScen) @@ -169,14 +175,16 @@ loadModeltest <- function( "user specified environment" else environmentName(envir), - ".\n", sep = "") + ".\n", sep = "" + ) loadCs2Data( mifScen = tmpPath$mifScen, mifHist = tmpPath$mifHist, cfgScen = tmpPath$cfgScen, cfgDefault = tmpPath$cfgDefault, - envir = envir) + envir = envir + ) cat("Done.\n") diff --git a/README.md b/README.md index 2ac9ade3..2ed5445c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # The REMIND R package (2nd generation) -R package **remind2**, version **1.130.0** +R package **remind2**, version **1.130.1** [![CRAN status](https://www.r-pkg.org/badges/version/remind2)](https://cran.r-project.org/package=remind2) [![R build status](https://github.com/pik-piam/remind2/workflows/check/badge.svg)](https://github.com/pik-piam/remind2/actions) [![codecov](https://codecov.io/gh/pik-piam/remind2/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/remind2) [![r-universe](https://pik-piam.r-universe.dev/badges/remind2)](https://pik-piam.r-universe.dev/builds) @@ -49,7 +49,7 @@ In case of questions / problems please contact Renato Rodrigues . +Rodrigues R, Baumstark L, Benke F, Dietrich J, Dirnaichner A, Duerrwaechter J, Führlich P, Giannousakis A, Hasse R, Hilaire J, Klein D, Koch J, Kowalczyk K, Levesque A, Malik A, Merfort A, Merfort L, Morena-Leiva S, Pehl M, Pietzcker R, Rauner S, Richters O, Rottoli M, Schötz C, Schreyer F, Siala K, Sörgel B, Spahr M, Strefler J, Verpoort P, Weigmann P (2024). _remind2: The REMIND R package (2nd generation)_. R package version 1.130.1, . A BibTeX entry for LaTeX users is @@ -58,7 +58,7 @@ A BibTeX entry for LaTeX users is title = {remind2: The REMIND R package (2nd generation)}, author = {Renato Rodrigues and Lavinia Baumstark and Falk Benke and Jan Philipp Dietrich and Alois Dirnaichner and Jakob Duerrwaechter and Pascal Führlich and Anastasis Giannousakis and Robin Hasse and Jérome Hilaire and David Klein and Johannes Koch and Katarzyna Kowalczyk and Antoine Levesque and Aman Malik and Anne Merfort and Leon Merfort and Simón Morena-Leiva and Michaja Pehl and Robert Pietzcker and Sebastian Rauner and Oliver Richters and Marianna Rottoli and Christof Schötz and Felix Schreyer and Kais Siala and Björn Sörgel and Mike Spahr and Jessica Strefler and Philipp Verpoort and Pascal Weigmann}, year = {2024}, - note = {R package version 1.130.0}, + note = {R package version 1.130.1}, url = {https://github.com/pik-piam/remind2}, } ``` diff --git a/man/loadModeltest.Rd b/man/loadModeltest.Rd index b581795a..a7efe778 100644 --- a/man/loadModeltest.Rd +++ b/man/loadModeltest.Rd @@ -6,7 +6,7 @@ \usage{ loadModeltest( envir = globalenv(), - namePattern = "^SSP2EU-AMT-", + namePattern = "^SSP2EU-.*-AMT$", folder = tempdir() ) } @@ -31,7 +31,7 @@ loadModeltest() ssp1 <- new.env() ssp2eu <- new.env() loadModeltest(ssp1, "^SSP1-AMT-") -loadModeltest(ssp2eu, "^SSP2EU-AMT-") +loadModeltest(ssp2eu, "^SSP2EU-.*-AMT$") ssp1$data ssp2eu$data }