From 7acae2a9f303eb77d2f4dc81e3c55df4e88041da Mon Sep 17 00:00:00 2001 From: orichters Date: Thu, 16 Feb 2023 13:45:24 +0100 Subject: [PATCH 1/3] better error message in readDefaultConfig, make chooseFromList more space-tolerant --- .buildlibrary | 2 +- .zenodo.json | 2 +- DESCRIPTION | 4 ++-- Makefile | 22 ++++++++++++---------- R/chooseFromList.R | 10 +++++++--- R/readDefaultConfig.R | 14 ++++++++++++-- README.md | 6 +++--- man/checkAppearance.Rd | 4 ++-- man/interfaceplot.Rd | 4 ++-- man/is.modularGAMS.Rd | 2 +- man/module.skeleton.Rd | 2 +- man/update_modules_embedding.Rd | 2 +- man/writeSets.Rd | 4 ++-- tests/testthat/test-chooseFromList.R | 4 ++++ 14 files changed, 51 insertions(+), 31 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index b0259cf..2244846 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '4653600' +ValidationKey: '4676364' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/.zenodo.json b/.zenodo.json index 213cf4d..913ea95 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -1,6 +1,6 @@ { "title": "gms: 'GAMS' Modularization Support Package", - "version": "0.24.0", + "version": "0.24.1", "description": "

A collection of tools to create, use and maintain modularized model code written in the modeling \n language 'GAMS' (). Out-of-the-box 'GAMS' does not come with support for modularized\n model code. This package provides the tools necessary to convert a standard 'GAMS' model to a modularized one\n by introducing a modularized code structure together with a naming convention which emulates local\n environments. In addition, this package provides tools to monitor the compliance of the model code with\n modular coding guidelines.<\/p>", "creators": [ { diff --git a/DESCRIPTION b/DESCRIPTION index 2a6b91f..8c3a1e4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: gms Type: Package Title: 'GAMS' Modularization Support Package -Version: 0.24.0 -Date: 2023-02-02 +Version: 0.24.1 +Date: 2023-02-16 Authors@R: c(person("Jan Philipp", "Dietrich", email = "dietrich@pik-potsdam.de", role = c("aut","cre")), person("David", "Klein", role = "aut"), person("Anastasis", "Giannousakis", role = "aut"), diff --git a/Makefile b/Makefile index 433f33e..c1e0c68 100644 --- a/Makefile +++ b/Makefile @@ -11,33 +11,35 @@ HELP_PARSING = 'm <- readLines("Makefile");\ help: ## Show this help. @Rscript -e $(HELP_PARSING) -build: ## Build the package using lucode2::buildLibrary() +build: ## Build the package using lucode2::buildLibrary(). Rscript -e 'lucode2::buildLibrary()' check: ## Build documentation and vignettes, run testthat tests, - ## and check if code etiquette is followed using lucode2::check() + ## and check if code etiquette is followed using lucode2::check(). Rscript -e 'lucode2::check()' test: ## Run testthat tests Rscript -e 'devtools::test(show_report = TRUE)' -lint: ## Check if code etiquette is followed using lucode2::lint() +lint: ## Check if code etiquette is followed using lucode2::lint(). ## Only checks files you changed. Rscript -e 'lucode2::lint()' -lint-all: ## Check if code etiquette is followed using lucode2::lint() +lint-all: ## Check if code etiquette is followed using lucode2::lint(). ## Checks all files. Rscript -e 'lucode2::lint(".")' -format: ## Apply auto-formatting to changed files and lint afterwards +format: ## Apply auto-formatting to changed files and lint afterwards. Rscript -e 'lucode2::autoFormat()' -format-all: ## Apply auto-formatting to all files and lint afterwards +format-all: ## Apply auto-formatting to all files and lint afterwards. Rscript -e 'lucode2::autoFormat(files=list.files("./R", full.names = TRUE, pattern = "\\.R"))' -install: ## Install the package locally via devtools::install() - Rscript -e 'devtools::install(upgrade = "never")' +install: ## Install the package locally via devtools::install() after + ## generating NAMESPACE and docs (see docs target). + Rscript -e 'roxygen2::roxygenize(); devtools::install(upgrade = "never")' -docs: ## Generate the package documentation (man/*.Rd files) via roxygen2::roxygenize(), - ## view the generated documentation with `?package::function` +docs: ## Generate the package documentation (man/*.Rd files) and + ## NAMESPACE via roxygen2::roxygenize(), view the generated + ## documentation with `?package::function`. Rscript -e 'roxygen2::roxygenize()' diff --git a/R/chooseFromList.R b/R/chooseFromList.R index faf6e12..4da116b 100644 --- a/R/chooseFromList.R +++ b/R/chooseFromList.R @@ -62,7 +62,7 @@ chooseFromList <- function(theList, type = "items", userinfo = NULL, addAllPatte } # interpret userinput and perform basic checks identifier <- try(eval(parse(text = paste("c(", userinput, ")")))) - if (! all(grepl("^[0-9,:]*$", userinput)) || inherits(identifier, "try-error")) { + if (! all(grepl("^[0-9,: ]*$", userinput)) || inherits(identifier, "try-error")) { message("Try again, you have to choose some numbers.") return(chooseFromList(originalList, type, userinfo, addAllPattern, returnBoolean, multiple)) } @@ -105,8 +105,12 @@ choosePatternFromList <- function(theList, type = "items", pattern = FALSE) { } id <- grep(pattern = pattern, theList) # lists all chosen and ask for the confirmation of the made choice - message("\n\nThe search pattern matches the following ", type, ":") - if (length(id) > 0) message(paste(paste(seq_along(id), theList[id], sep = ": "), collapse = "\n")) + if (length(id) > 0) { + message("\n\nThe search pattern matches the following ", type, ":") + message(paste(paste(seq_along(id), theList[id], sep = ": "), collapse = "\n")) + } else { + message("Oops. You didn't select anything.") + } if (confirmchoice) { message("\nAre you sure these are the right ", type, "? (y/n): ") if (! getLine() %in% c("y", "Y")) { diff --git a/R/readDefaultConfig.R b/R/readDefaultConfig.R index 5066447..b956c46 100644 --- a/R/readDefaultConfig.R +++ b/R/readDefaultConfig.R @@ -15,9 +15,19 @@ readDefaultConfig <- function(path) { # read in settings from main.gms first cfg <- list() - cfg$gms <- as.list(readSettings(paste0(path, "/", "main.gms"))) + fileMain <- file.path(path, "main.gms") + if (file.exists(fileMain)) { + cfg$gms <- as.list(readSettings(fileMain)) + } else { + stop("readDefaultConfig cannot find main.gms in ", normalizePath(path)) + } # overwrite with settings from default.cfg env <- new.env() - source(paste0(path, "/", "config/default.cfg"), local = env) # nolint: undesirable_function_linter + fileDefault <- file.path(path, "config", "default.cfg") + if (file.exists(fileDefault)) { + source(fileDefault, local = env) # nolint: undesirable_function_linter + } else { + stop("readDefaultConfig cannot find config/default.cfg in ", normalizePath(path)) + } return(modifyList(cfg, env$cfg, keep.null = TRUE)) } diff --git a/README.md b/README.md index 54e11d0..ba49514 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 'GAMS' Modularization Support Package -R package **gms**, version **0.24.0** +R package **gms**, version **0.24.1** [![CRAN status](https://www.r-pkg.org/badges/version/gms)](https://cran.r-project.org/package=gms) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4390032.svg)](https://doi.org/10.5281/zenodo.4390032) [![R build status](https://github.com/pik-piam/gms/workflows/check/badge.svg)](https://github.com/pik-piam/gms/actions) [![codecov](https://codecov.io/gh/pik-piam/gms/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/gms) [![r-universe](https://pik-piam.r-universe.dev/badges/gms)](https://pik-piam.r-universe.dev/builds) @@ -43,7 +43,7 @@ In case of questions / problems please contact Jan Philipp Dietrich , R package version 0.24.0, . +Dietrich J, Klein D, Giannousakis A, Beier F, Koch J, Baumstark L, Pflüger M, Richters O (2023). _gms: 'GAMS' Modularization Support Package_. doi: 10.5281/zenodo.4390032 (URL: https://doi.org/10.5281/zenodo.4390032), R package version 0.24.1, . A BibTeX entry for LaTeX users is @@ -52,7 +52,7 @@ A BibTeX entry for LaTeX users is title = {gms: 'GAMS' Modularization Support Package}, author = {Jan Philipp Dietrich and David Klein and Anastasis Giannousakis and Felicitas Beier and Johannes Koch and Lavinia Baumstark and Mika Pflüger and Oliver Richters}, year = {2023}, - note = {R package version 0.24.0}, + note = {R package version 0.24.1}, doi = {10.5281/zenodo.4390032}, url = {https://github.com/pik-piam/gms}, } diff --git a/man/checkAppearance.Rd b/man/checkAppearance.Rd index 3fef632..ce9959b 100644 --- a/man/checkAppearance.Rd +++ b/man/checkAppearance.Rd @@ -11,8 +11,8 @@ checkAppearance(x) } \value{ A list with four elements: appearance, setappearance, type and -warnings. Appearance is a matrix containing values which indicate whether an -object appears in a part of the code or not (e.g. indicates whether "vm_example" +warnings. Appearance is a matrix containing values which indicate whether an +object appears in a part of the code or not (e.g. indicates whether "vm_example" appears in realization "on" of module "test" or not.). 0 means that it does not appear, 1 means that it appears in the code and 2 means that it appears in the not_used.txt. setappearance contains the same information but for sets instead of other diff --git a/man/interfaceplot.Rd b/man/interfaceplot.Rd index 20be1c5..10e5801 100644 --- a/man/interfaceplot.Rd +++ b/man/interfaceplot.Rd @@ -83,8 +83,8 @@ that do not arrive at one of the group's nodes are ignored \item "outgoing_to_no_return" edges that departing from nodes outside of the group and not ending at nodes within the group are ignored }} An example: \code{list(list(name = "highlight", nodes = "welfare", color = "#ff8f00", - shape = "ellipse", edges_to_highlight = "outgoing", edges_to_ignore = - "outside"))}.} +shape = "ellipse", edges_to_highlight = "outgoing", edges_to_ignore = +"outside"))}.} \item{max_length_node_names}{NULL (default value) or an integer n giving the maximum number of characters allowed in the node names. If not NULL, node diff --git a/man/is.modularGAMS.Rd b/man/is.modularGAMS.Rd index c1d66d1..5f4e165 100644 --- a/man/is.modularGAMS.Rd +++ b/man/is.modularGAMS.Rd @@ -9,7 +9,7 @@ is.modularGAMS(path = ".", version = FALSE, modulepath = "modules/") \arguments{ \item{path}{path to the main folder of the model} -\item{version}{if TRUE returns the version of the modular structure or FALSE, +\item{version}{if TRUE returns the version of the modular structure or FALSE, otherwise returns a boolean indicating whether it is modular or not.} \item{modulepath}{Module path within the model (relative to the model main diff --git a/man/module.skeleton.Rd b/man/module.skeleton.Rd index a33452d..912d2fd 100644 --- a/man/module.skeleton.Rd +++ b/man/module.skeleton.Rd @@ -46,7 +46,7 @@ Module phases are automatically detected checking the main code of the model, but not checking code in modules. If you want to use additional phases which are only included within a module, you need to specify them manually by adding a comment into your gams code indicating that there is an -additional phase. The syntax is "* !add_phase!: \if{html}{\out{}}", e.g. "* +additional phase. The syntax is "* !add_phase!: ", e.g. "* !add_phase!: new_phase" } \examples{ diff --git a/man/update_modules_embedding.Rd b/man/update_modules_embedding.Rd index 98769a4..c2e27ec 100644 --- a/man/update_modules_embedding.Rd +++ b/man/update_modules_embedding.Rd @@ -35,7 +35,7 @@ Module phases are automatically detected checking the main code of the model, but not checking code in modules. If you want to use additional phases which are only included within a module, you need to specify them manually by adding a comment into your gams code indicating that there is an -additional phase. The syntax is "* !add_phase!: \if{html}{\out{}}", e.g. "* +additional phase. The syntax is "* !add_phase!: ", e.g. "* !add_phase!: new_phase" } \examples{ diff --git a/man/writeSets.Rd b/man/writeSets.Rd index 8739833..0431c23 100644 --- a/man/writeSets.Rd +++ b/man/writeSets.Rd @@ -7,8 +7,8 @@ writeSets(sets, file = NULL) } \arguments{ -\item{sets}{a list of sets where every set is another list consisting of -three entries: name (set name as character), desc (set description as +\item{sets}{a list of sets where every set is another list consisting of +three entries: name (set name as character), desc (set description as character) and items (set elements, either as character vector or data.frame)} \item{file}{Name of the file the set declarations should be written to. If diff --git a/tests/testthat/test-chooseFromList.R b/tests/testthat/test-chooseFromList.R index 8b8c045..f9c7423 100644 --- a/tests/testthat/test-chooseFromList.R +++ b/tests/testthat/test-chooseFromList.R @@ -11,10 +11,14 @@ test_that("check various chooseFromList settings", { c("B", "1")) expect_identical(unname(chooseFromList(theList, returnBoolean = TRUE, userinput = "3,5")), c(FALSE, TRUE, FALSE, TRUE, FALSE, FALSE)) + expect_identical(unname(chooseFromList(theList, returnBoolean = TRUE, userinput = " 3, 5 ")), + c(FALSE, TRUE, FALSE, TRUE, FALSE, FALSE)) expect_identical(chooseFromList(theList, userinput = "1"), theList) expect_identical(chooseFromList(theList, addAllPattern = FALSE, userinput = "1"), theList[1]) + expect_identical(chooseFromList(theList, addAllPattern = FALSE, userinput = " 1 : 1 "), + theList[1]) expect_identical(unname(chooseFromList(theList, userinput = "1", returnBoolean = TRUE)), rep(TRUE, length(theList))) expect_identical(chooseFromList(theList, userinput = toString(length(theList) + 2)), From 64e92c86991ecc33e7fc8d2fbd16475108e72f97 Mon Sep 17 00:00:00 2001 From: orichters Date: Fri, 17 Feb 2023 16:48:38 +0100 Subject: [PATCH 2/3] buildLibrary() --- .buildlibrary | 2 +- .zenodo.json | 2 +- DESCRIPTION | 2 +- README.md | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index df355a3..38113ab 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '4676605' +ValidationKey: '4696010' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/.zenodo.json b/.zenodo.json index 913ea95..c9a9687 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -1,6 +1,6 @@ { "title": "gms: 'GAMS' Modularization Support Package", - "version": "0.24.1", + "version": "0.24.2", "description": "

A collection of tools to create, use and maintain modularized model code written in the modeling \n language 'GAMS' (). Out-of-the-box 'GAMS' does not come with support for modularized\n model code. This package provides the tools necessary to convert a standard 'GAMS' model to a modularized one\n by introducing a modularized code structure together with a naming convention which emulates local\n environments. In addition, this package provides tools to monitor the compliance of the model code with\n modular coding guidelines.<\/p>", "creators": [ { diff --git a/DESCRIPTION b/DESCRIPTION index 0eab3ed..1eb6752 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: gms Type: Package Title: 'GAMS' Modularization Support Package -Version: 0.24.1 +Version: 0.24.2 Date: 2023-02-17 Authors@R: c(person("Jan Philipp", "Dietrich", email = "dietrich@pik-potsdam.de", role = c("aut","cre")), person("David", "Klein", role = "aut"), diff --git a/README.md b/README.md index ba49514..b7c876d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 'GAMS' Modularization Support Package -R package **gms**, version **0.24.1** +R package **gms**, version **0.24.2** [![CRAN status](https://www.r-pkg.org/badges/version/gms)](https://cran.r-project.org/package=gms) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4390032.svg)](https://doi.org/10.5281/zenodo.4390032) [![R build status](https://github.com/pik-piam/gms/workflows/check/badge.svg)](https://github.com/pik-piam/gms/actions) [![codecov](https://codecov.io/gh/pik-piam/gms/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/gms) [![r-universe](https://pik-piam.r-universe.dev/badges/gms)](https://pik-piam.r-universe.dev/builds) @@ -43,7 +43,7 @@ In case of questions / problems please contact Jan Philipp Dietrich . +Dietrich J, Klein D, Giannousakis A, Beier F, Koch J, Baumstark L, Pflüger M, Richters O (2023). _gms: 'GAMS' Modularization Support Package_. doi: 10.5281/zenodo.4390032 (URL: https://doi.org/10.5281/zenodo.4390032), R package version 0.24.2, . A BibTeX entry for LaTeX users is @@ -52,7 +52,7 @@ A BibTeX entry for LaTeX users is title = {gms: 'GAMS' Modularization Support Package}, author = {Jan Philipp Dietrich and David Klein and Anastasis Giannousakis and Felicitas Beier and Johannes Koch and Lavinia Baumstark and Mika Pflüger and Oliver Richters}, year = {2023}, - note = {R package version 0.24.1}, + note = {R package version 0.24.2}, doi = {10.5281/zenodo.4390032}, url = {https://github.com/pik-piam/gms}, } From 2a1d3531b527c2b7cd87a8a7e7881ed0c14628a1 Mon Sep 17 00:00:00 2001 From: orichters Date: Thu, 2 Mar 2023 13:44:18 +0100 Subject: [PATCH 3/3] improve description of returnBoolean --- .buildlibrary | 2 +- .zenodo.json | 2 +- DESCRIPTION | 4 ++-- R/chooseFromList.R | 6 ++++-- README.md | 6 +++--- man/chooseFromList.Rd | 6 ++++-- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index 38113ab..b9c5e1d 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '4696010' +ValidationKey: '4718574' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/.zenodo.json b/.zenodo.json index c9a9687..7478bae 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -1,6 +1,6 @@ { "title": "gms: 'GAMS' Modularization Support Package", - "version": "0.24.2", + "version": "0.24.3", "description": "

A collection of tools to create, use and maintain modularized model code written in the modeling \n language 'GAMS' (). Out-of-the-box 'GAMS' does not come with support for modularized\n model code. This package provides the tools necessary to convert a standard 'GAMS' model to a modularized one\n by introducing a modularized code structure together with a naming convention which emulates local\n environments. In addition, this package provides tools to monitor the compliance of the model code with\n modular coding guidelines.<\/p>", "creators": [ { diff --git a/DESCRIPTION b/DESCRIPTION index 1eb6752..73fb24c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: gms Type: Package Title: 'GAMS' Modularization Support Package -Version: 0.24.2 -Date: 2023-02-17 +Version: 0.24.3 +Date: 2023-03-02 Authors@R: c(person("Jan Philipp", "Dietrich", email = "dietrich@pik-potsdam.de", role = c("aut","cre")), person("David", "Klein", role = "aut"), person("Anastasis", "Giannousakis", role = "aut"), diff --git a/R/chooseFromList.R b/R/chooseFromList.R index 4da116b..68f95b4 100644 --- a/R/chooseFromList.R +++ b/R/chooseFromList.R @@ -7,8 +7,10 @@ #' @param type string in plural shown to user to understand what they have to choose #' @param userinfo string printed to the user before choosing #' @param addAllPattern boolean whether 'all' and 'Search by pattern' options are added -#' @param returnBoolean TRUE: returns array with dimension of theList with FALSE and TRUE -#' FALSE: returns selected entries of theList +#' @param returnBoolean TRUE: returns array with dimension of theList with FALSE and TRUE, +#' which erases the order in which entries were selected +#' FALSE: returns selected entries of theList, conserving the order +#' in which entries were selected #' @param multiple TRUE: allows to select multiple entries. FALSE: no #' @param userinput string provided by the user. If not supplied, user is asked (mainly for testing) #' diff --git a/README.md b/README.md index b7c876d..9c883b3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 'GAMS' Modularization Support Package -R package **gms**, version **0.24.2** +R package **gms**, version **0.24.3** [![CRAN status](https://www.r-pkg.org/badges/version/gms)](https://cran.r-project.org/package=gms) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4390032.svg)](https://doi.org/10.5281/zenodo.4390032) [![R build status](https://github.com/pik-piam/gms/workflows/check/badge.svg)](https://github.com/pik-piam/gms/actions) [![codecov](https://codecov.io/gh/pik-piam/gms/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/gms) [![r-universe](https://pik-piam.r-universe.dev/badges/gms)](https://pik-piam.r-universe.dev/builds) @@ -43,7 +43,7 @@ In case of questions / problems please contact Jan Philipp Dietrich . +Dietrich J, Klein D, Giannousakis A, Beier F, Koch J, Baumstark L, Pflüger M, Richters O (2023). _gms: 'GAMS' Modularization Support Package_. doi: 10.5281/zenodo.4390032 (URL: https://doi.org/10.5281/zenodo.4390032), R package version 0.24.3, . A BibTeX entry for LaTeX users is @@ -52,7 +52,7 @@ A BibTeX entry for LaTeX users is title = {gms: 'GAMS' Modularization Support Package}, author = {Jan Philipp Dietrich and David Klein and Anastasis Giannousakis and Felicitas Beier and Johannes Koch and Lavinia Baumstark and Mika Pflüger and Oliver Richters}, year = {2023}, - note = {R package version 0.24.2}, + note = {R package version 0.24.3}, doi = {10.5281/zenodo.4390032}, url = {https://github.com/pik-piam/gms}, } diff --git a/man/chooseFromList.Rd b/man/chooseFromList.Rd index 992f98d..d08b035 100644 --- a/man/chooseFromList.Rd +++ b/man/chooseFromList.Rd @@ -23,8 +23,10 @@ chooseFromList( \item{addAllPattern}{boolean whether 'all' and 'Search by pattern' options are added} -\item{returnBoolean}{TRUE: returns array with dimension of theList with FALSE and TRUE -FALSE: returns selected entries of theList} +\item{returnBoolean}{TRUE: returns array with dimension of theList with FALSE and TRUE, +which erases the order in which entries were selected +FALSE: returns selected entries of theList, conserving the order +in which entries were selected} \item{multiple}{TRUE: allows to select multiple entries. FALSE: no}