From 2b420810a6b1fd5ed70c55c5b97d2d79b7a9d9fb Mon Sep 17 00:00:00 2001 From: Simon Krogmann Date: Sat, 10 Oct 2026 11:36:21 +0200 Subject: [PATCH 1/3] Move runtime check to tests --- scripts/start/prepare.R | 25 ------------------------- tests/testthat/test_03-quick.R | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/scripts/start/prepare.R b/scripts/start/prepare.R index 6332a3abc2..d351e1d3d2 100644 --- a/scripts/start/prepare.R +++ b/scripts/start/prepare.R @@ -5,27 +5,6 @@ # | REMIND License Exception, version 1.0 (see LICENSE file). # | Contact: remind@pik-potsdam.de -library(stringr) -library(glue) - -#' check if delimiters only occur paired in a file. No nesting allowed. -#' -#' @param file_path where to check -#' @param openDelim string of the open delimiter -#' @param closeDelim string of the closing delimiter -#' -#' @return boolean -validatePairedDelimiters <- function(file_path, openDelim = "$onDelim", closeDelim = "$offDelim") { - content <- paste(readLines(file_path, warn = FALSE), collapse = "\n") - matches <- str_extract_all(content, glue("{str_escape(openDelim)}|{str_escape(closeDelim)}"))[[1]] - - # Build expected alternating sequence - expected <- rep_len(c(openDelim, closeDelim), length(matches)) - - # Valid if matches alternating pattern AND count is even - return(length(matches) %% 2 == 0 && identical(matches, expected)) -} - prepare <- function() { timePrepareStart <- Sys.time() @@ -251,10 +230,6 @@ prepare <- function() { # $offlisting appears in main.gms but the current process does not let it survive into full.gms # therefore all cs3r/cs4r file contents are dumped directly into the full.lst # to avoid this we add $offlisting manually at $onDelim present at each include of a cs4r/cs3r - # first do a sanity check on "$onDelim", "$offDelim" - if (!validatePairedDelimiters(dumpFilePath, "$onDelim", "$offDelim")) { - stop("We either have nested $onDelim/$offDelim blocks (unnecessarily large) or $onDelim/$offDelim are not correctly matched.") - } lucode2::manipulateFile(dumpFilePath, list(c("$onDelim", "$offlisting\n$onDelim"), c("$offDelim", "$offDelim\n$onlisting")), fixed = TRUE) file.rename(from[exist], to[exist]) diff --git a/tests/testthat/test_03-quick.R b/tests/testthat/test_03-quick.R index 77beb7f7e6..310a1db2ff 100644 --- a/tests/testthat/test_03-quick.R +++ b/tests/testthat/test_03-quick.R @@ -4,10 +4,36 @@ # | AGPL-3.0, you are granted additional permissions described in the # | REMIND License Exception, version 1.0 (see LICENSE file). # | Contact: remind@pik-potsdam.de + +library(stringr) +library(glue) + +#' check if delimiters only occur paired in a file. No nesting allowed. +#' +#' @param file_path where to check +#' @param openDelim string of the open delimiter +#' @param closeDelim string of the closing delimiter +#' +#' @return boolean +validatePairedDelimiters <- function(file_path, openDelim = "$onDelim", closeDelim = "$offDelim") { + content <- paste(readLines(file_path, warn = FALSE), collapse = "\n") + matches <- str_extract_all(content, glue("{str_escape(openDelim)}|{str_escape(closeDelim)}"))[[1]] + + # Build expected alternating sequence + expected <- rep_len(c(openDelim, closeDelim), length(matches)) + + # Valid if matches alternating pattern AND count is even + return(length(matches) %% 2 == 0 && identical(matches, expected)) +} + test_that("start.R config/tests/scenario_config_quick.csv works", { skipIfPreviousFailed() output <- localSystem2("Rscript", c("start.R", "config/tests/scenario_config_quick.csv")) printIfFailed(output) expectSuccessStatus(output) expect_true(file.exists("../../output/testOneRegi/REMIND_generic_testOneRegi.mif")) + + # Check if we have nested $onDelim/$offDelim blocks (unnecessarily large) or $onDelim/$offDelim are not correctly matched. + # prepare.R contains some string manipulation that might break if this does not hold + expect_true(validatePairedDelimiters("../../output/testOneRegi/full.gms", "$onDelim", "$offDelim")) }) From f48b63b4b1eacdc30744b60ee103e22f1632cf2b Mon Sep 17 00:00:00 2001 From: Simon Krogmann Date: Sat, 10 Oct 2026 11:41:14 +0200 Subject: [PATCH 2/3] Docs --- .gitignore | 3 +++ tutorials/01_GettingREMIND.md | 2 +- tutorials/02a_RunningREMINDLocally.md | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 23e1979c4c..d896465190 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,9 @@ # ignore libreoffice lock files .~*# +# ignore Mac OS files +.DS_Store + # Ignore everything in "input" folders input/ !input/files diff --git a/tutorials/01_GettingREMIND.md b/tutorials/01_GettingREMIND.md index ef89b6e2eb..31768f4d47 100644 --- a/tutorials/01_GettingREMIND.md +++ b/tutorials/01_GettingREMIND.md @@ -11,7 +11,7 @@ REQUIREMENTS - input data - git - GAMS >= 39.1.0 with CONOPT license -- R >= 4.0. We recommend R 4.3.2. +- R >= 4.0. We recommend R 4.6.1. - Windows only: RTools - LaTeX - pandoc diff --git a/tutorials/02a_RunningREMINDLocally.md b/tutorials/02a_RunningREMINDLocally.md index 3126e00aa8..3a664eee29 100644 --- a/tutorials/02a_RunningREMINDLocally.md +++ b/tutorials/02a_RunningREMINDLocally.md @@ -9,7 +9,7 @@ Check the general system requirements in [Section 1: Getting REMIND](01_GettingR - Installed python version must be `< 3.11`. We recommend a python version `3.10.X` as it is closest to being up-to-date while remaining REMIND compatible. To check your python version run `python --version` in a terminal of your choice - There are some additional recommendations for running REMIND locally on a **Windows systems**: - - To avoid lengthy compilation times during preparation for your remind run, we recommend to use a version of R for which most R-packages that REMIND depends on, are available as binary packages. This is typically the case for recent versions of R, currently `4.2.X` or `4.3.X`. To check your R version run `R --version` in a terminal of your choice + - To avoid lengthy compilation times during preparation for your remind run, we recommend to use a version of R for which most R-packages that REMIND depends on, are available as binary packages. This is typically the case for recent versions of R, currently `4.6.X`. To check your R version run `R --version` in a terminal of your choice - As mentioned in the general system requirements, GAMS must be installed. On Windows, make sure that the path to GAMS applications is in your PATH environment variable - We recommend to use PowerShell rather than the standard command prompt From 3cd88cee18abdffb0db74de9551567fcb26c41a8 Mon Sep 17 00:00:00 2001 From: Simon Krogmann Date: Wed, 14 Oct 2026 17:32:05 +0200 Subject: [PATCH 3/3] Add make command to upgrade renv --- Makefile | 10 ++++++++++ renv/activate.R | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 20753bab05..011ebefb39 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,16 @@ update-renv-all: ## Upgrade all packages (including CRAN packages) in your renv ## to the respective latest release, write renv.lock archive @Rscript -e 'renv::update(); piamenv::archiveRenv()' +upgrade-renv-version: ## Upgrade the renv version and remove + @Rscript -e 'renv::upgrade()' + @if grep -qE 'attr\(version, *"md5"\) *<- *"[^"]*"' renv/activate.R; then \ + sed -i -E 's/attr\(version, *"md5"\) *<- *"[^"]*"/attr(version, "md5") <- NULL/' renv/activate.R; \ + echo "Successfully removed hash from renv/activate.R"; \ + else \ + echo "Error: Target pattern 'attr(version, \"md5\") <- \"...\"' not found in renv/activate.R" >&2; \ + exit 1; \ + fi + revert-dev-packages: ## All PIK-PIAM packages that are development versions, i.e. ## that have a non-zero fourth version number component, are ## reverted to the highest version lower than the diff --git a/renv/activate.R b/renv/activate.R index 3f52a662a6..291437fd35 100644 --- a/renv/activate.R +++ b/renv/activate.R @@ -2,7 +2,7 @@ local({ # the requested version of renv - version <- "1.3.0" + version <- "1.3.1" attr(version, "md5") <- NULL attr(version, "sha") <- NULL