Welcome to the GDXRRW home page! GDXRRW is an interface between GAMS and R. It includes functions to transfer data between GDX and R and a function to call gams from within R.
From this site you can download versions of the GDXRRW package for all supported architectures. I also expect to collect some of the common questions and issues about GDXRRW and put them into a FAQ available here.
We would love to get feedback on GDXRRW. Please direct your questions, comments, and suggestions to R@gams.com.
Latest stable version
Latest trunk (development) version
Older versions
_r351
): [ OS X 64-bit binary] [Windows 32- and 64-bit binary]
The GDXRRW package depends on the reshape2 package. Before installing GDXRRW you should install the reshape2 package, e.g. by running install.packages(“reshape2”)
installing from source: In the R environment, navigate to the directory containing the source package file (see download links above), and, substituting the version number for a.b.c, type:
install.packages(“gdxrrw_a.b.c.tar.gz”)
or, depending on the version of R,
install.packages(“gdxrrw_a.b.c.tar.gz”,repos=NULL,type=“source”)
Linux installation: In the R environment, navigate to the directory containing the binary package file (see download links above), and, substituting the version number for a.b.c and the appropriate platform info, type:
install.packages(“gdxrrw_a.b.c_R_platform-info.tar.gz”)
or, depending on the version of R,
install.packages(“gdxrrw_a.b.c_R_platform-info.tar.gz”,repos=NULL)
OS X installation: In the R environment, navigate to the directory containing the binary package file (see download links above), and, substituting the version number for a.b.c, type:
install.packages(“gdxrrw_a.b.c.tgz”)
or, depending on the version of R,
install.packages(“gdxrrw_a.b.c.tgz”,repos=NULL)
Windows installation: In the R environment, navigate to the directory containing the binary package file (see download links above), and, substituting the version number for a.b.c, type:
install.packages(“gdxrrw_a.b.c.zip”)
or, depending on the version of R,
install.packages(“gdxrrw_a.b.c.zip”,repos=NULL)
If you are relatively new to R you may not have installed R packages before. More complete documentation on installing and managing packages is available in the R manual, but you can also follow these simple steps for getting set up to install packages in user space.
Sys.getenv(“R_LIBS_USER”)
.libPaths()
install.packages
commands above
The Safari browser un-gzips the .tgz
files R uses for packages on the Mac. There are several ways to work around this issue: you can change this behavior in Safari by changing your preferences (as described here), use a different browser like Chrome or Firefox, use the .tgz
files included in the GAMS distribution, or use a command line tool like curl
to download the .tgz
files.
In some cases a source package install will fail when using a tar.gz
file as input, with a message like Error in rawToChar(block[seq_len(ns)])
. This has been traced to a problem with the untar() function in some R distributions. As a workaround, you can manually un-tar and re-tar the source package, e.g.:
After you install GDXRRW you may want to verify that the installation is functioning correctly. The GDXRRW package is not loaded by default, so before the package is available you must load it. This is easily done with the library(gdxrrw)
command. Once the package is loaded, you can get help on the package as a whole (help(gdxrrw)
) or the functions or data elements in the package (e.g. help(igdx)
).
For GDXRRW to work it must load shared libraries from the GAMS system directory. One common problem is a failure to find the GAMS system directory and these shared libraries. The igdx
command can be used to show what GAMS system directory GDXRRW has found (igdx()
) and to point GDXRRW to a particular GAMS system directory if so desired (igdx(“/usr/local/gams/24.4.1”)
). Depending on your system setup, environment variables, and how you start R, GDXRRW may not need any help finding the GAMS system directory, but the igdx
command allows this binding to be queried and customized if desired.
The R sessionInfo()
command tells you the version number of packages you have loaded, including gdxrrw. If you need SVN revision info, some commands print that, e.g. rgdx(“?”)
.
The help pages for the other GDXRRW functions include examples that you can run to quickly verify your system is working.
If you are seeing GDXRRW for the first time you should look at the examples and tests that come with GDXRRW. For example, each of the functions wgdx
, rgdx
, igdx
, and gams
comes with integrated help and examples that can be accessed in the usual way within the R environment, e.g.: help(rgdx)
. In addition, more complete tests and more substantive examples are included in the gdxrrw
package. For more recent package versions (0.6.0 and following), package tests are collected in the tests
directory. Earlier versions put the tests in extdata
. The sample commands below assume a recent version and sufficient access permission in the package install directory. If you lack such permission copy the files before using them. Some helpful R commands for testing are:
setwd (paste0(path.package('gdxrrw'),'/tests'))
tAll.R
script (source(“tAll.R”)
to run the tests
Some examples are collected in the extdata
directory:
setwd (paste0(path.package('gdxrrw'),'/extdata'))
TSP
, execute the egTSP.R
script to export data for a traveling salesman problem to GAMS, solve it, and return the solution to R for plottingLS
, run the egLeastSquares.gms
model from GAMS - this calls R as part of the GAMS run to do the data fitting and return the results
R provides multiple ways to customize the environment at startup, e.g. to start with the GDXRRW package loaded. I prefer to use the .Rprofile
script that is executed from the HOME directory when R starts up.
help(Startup)
Sys.glob(“~”)
.First <- function() { library(gdxrrw) ; igdx("/home/sdirkse/gams/24.4.1")}
.First <- function() { library(gdxrrw) a <- R.Version()$arch if (a == "x86_64") igdx("/gams_64/24.4.1") else igdx("/gams_32/24.4.1") }
Sys.getenv
:Sys.getenv(“R_LIBS_USER”)
helps to find user-installed packagesSys.getenv(“R_USER”)
helps to locate the .Rprofile file, especially on WindowsR.Version
rgdx.param
: change default name of value column from val to valuegams()
crashed or failed if no data is passed backrgdx.param
: better to use the recast
function from the reshape
packagergdx
returns the symbol name using the case from GDX, not the case as specified in the searchwgdx.df
, wgdx.scalar
, and wgdx.lst
gams(x)
so x
is like the command line, not just the GAMS source file namegdxInfo (gdxName,dump=TRUE,returnList=FALSE,returnDF=FALSE)
rgdx.scalar
for zero scalarswgdx.reshape
wrapper to facilitate reshaping/preparing dataframes for writing to GDX. This wrapper is subject to change, and comments are welcomed. A vignette is available [here].silent=FALSE
arg to igdx
gdxInfo
useDomInfo=TRUE
to rgdx
family$domains
to rgdx
output: returns domain info from GDX file if availableextdata
to tests
(r50629)