Skip to content
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: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
# ignore libreoffice lock files
.~*#

# ignore Mac OS files
.DS_Store

# Ignore everything in "input" folders
input/
!input/files
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion renv/activate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 0 additions & 25 deletions scripts/start/prepare.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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])
Expand Down
26 changes: 26 additions & 0 deletions tests/testthat/test_03-quick.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
2 changes: 1 addition & 1 deletion tutorials/01_GettingREMIND.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tutorials/02a_RunningREMINDLocally.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading