R/settingsCheck.R

Defines functions settingsCheck

Documented in settingsCheck

#' settingsCheck
#'
#' Checks GAMS setglobals in code for consistency. Creates a warning if a
#' setglobal command for an existing module is missing or a module is set to a
#' realization which does not exist.
#'
#'
#' @param path path of the main folder of the model
#' @param modulepath path to the module folder relative to "path"
#' @param fileName name of the file containing setglobals, relative to "path"
#' @return Nothing is returned.
#' @author Jan Philipp Dietrich
#' @export
#' @seealso \code{\link{codeCheck}}
settingsCheck <- function(path = ".", modulepath = "modules", fileName = "main.gms") {
  s <- readSetglobals(path(path, fileName))
  m <- getModules(modulepath)
  dimnames(m)[[1]] <- m[, "name"]
  not_set <- m[!(m[, "name"] %in% names(s)), "name"]
  if (length(not_set) > 0) {
    for (n in not_set) warning("setglobal for module ", n, " could not be found! This module is not executed at all!",
                              call. = FALSE)
  }
  modules <- names(s)[(names(s) %in% m[, "name"])]
  for (x in modules) {
    realizations <- strsplit(m[x, "realizations"], ",")[[1]]
    if (!(s[x] %in% realizations)) warning("Non-existent realization \"", s[x], "\" set for module \"", x, "\"!",
                                          call. = FALSE)
  }
}
pik-piam/gms documentation built on Oct. 20, 2024, 1:17 a.m.