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 <- readLines(file,warn=FALSE)
  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] *([^ ]*) *([^ ]*)( .*|)$"
  out <- gsub(pattern,"\\2",f)
  names(out) <- gsub(pattern,"\\1",f)
  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 July 2, 2020, 2:36 a.m.