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 bugs in loadModeltest #510

Merged
merged 3 commits into from
Jan 25, 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
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -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'
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: '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
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: 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", , "[email protected]", role = c("aut", "cre")),
person("Lavinia", "Baumstark", role = "aut"),
Expand Down Expand Up @@ -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
44 changes: 26 additions & 18 deletions R/loadModeltest.R
Original file line number Diff line number Diff line change
@@ -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) # nolint
sel <- which(file.exists(possibleProjectLocations))[1]
if (is.na(sel)) stop("Cannot determine a path to projects on the cluster.")
possibleProjectLocations[sel]
Expand All @@ -13,14 +13,15 @@ getProjectPath <- function(project = "remind") {
#' @importFrom dplyr bind_cols
getNewsestModeltests <- function(namePattern, requireMif) {

modeltestOutPath <- file.path(getProjectPath(), "modeltests/output")
modeltestOutPath <- file.path(getProjectPath(), "modeltests", "remind", "output")
entries <- dir(modeltestOutPath)
allRunNames <-
entries %>%
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) %>%
Expand All @@ -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 %>%
Expand All @@ -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()
Expand All @@ -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))
}
Expand Down Expand Up @@ -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))
Expand All @@ -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 "),
Expand All @@ -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)
Expand All @@ -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")

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -49,7 +49,7 @@ In case of questions / problems please contact Renato Rodrigues <renato.rodrigue

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

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.0, <URL: https://github.com/pik-piam/remind2>.
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, <https://github.com/pik-piam/remind2>.

A BibTeX entry for LaTeX users is

Expand All @@ -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},
}
```
4 changes: 2 additions & 2 deletions man/loadModeltest.Rd

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

Loading