R/readSetglobals.R

Defines functions readSetglobals

Documented in readSetglobals

#' readSetglobals
#'
#' Reads all setglobals given in a GAMS code and returns them.
#'
#'
#' @param file A gams file or a vector containing GAMS code.
#' @return A vector of values the setglobal variables are set to with setglobal
#' variables as names.
#' @author Jan Philipp Dietrich
#' @seealso \code{\link{readDeclarations}}
readSetglobals <- function(file) {
  f <- readFileOrVector(file)
  f <- suppressWarnings(grep("^\\$[sS][eE][tT][gG][lL][oO][bB][aA][lL]", f, value = TRUE))
  pattern <- "^\\$[sS][eE][tT][gG][lL][oO][bB][aA][lL]\\s*([^\\s]*)\\s*(.*?)\\s*(!!.*)?$"
  out <- gsub(pattern, "\\2", f, perl = TRUE)
  names(out) <- gsub(pattern, "\\1", f, perl = TRUE)
  return(out)
}

Try the gms package in your browser

Any scripts or data that you put into this service are public.

gms documentation built on June 29, 2024, 9:07 a.m.