Title: | IO for GAMS GDX Files using data.table |
---|---|
Description: | Interfaces GAMS data (*.gdx) files with data.tables using the GAMS R package gdxrrw. The gdxrrw package is available on the GAMS wiki: <https://support.gams.com/doku.php?id=gdxrrw:interfacing_gams_and_r>. |
Authors: | Alois Dirnaichner [aut, cre] |
Maintainer: | Alois Dirnaichner <[email protected]> |
License: | MIT + file LICENCE |
Version: | 0.1.0 |
Built: | 2024-11-20 03:19:09 UTC |
Source: | https://github.com/loisel/gdxdt |
Provided the raw output from gdxrrw::rgdx, create a data.table with the correct UEL dimensions.
raw2dt(full_data)
raw2dt(full_data)
full_data |
a list as given by gdxrrw::rgdx. |
a data.table
## Not run: # prepare raw data dt <- as.data.table(mtcars, keep.rownames = TRUE) writegdx("test.gdx", dt, "test_var", valcol="wt", uelcols="rn", type="parameter") data <- gdxrrw::rgdx("test.gdx", list(name="test_var")) # data.table from raw data table <- raw2dt(data) ## End(Not run)
## Not run: # prepare raw data dt <- as.data.table(mtcars, keep.rownames = TRUE) writegdx("test.gdx", dt, "test_var", valcol="wt", uelcols="rn", type="parameter") data <- gdxrrw::rgdx("test.gdx", list(name="test_var")) # data.table from raw data table <- raw2dt(data) ## End(Not run)
Save to a GAMS gdx file. Works on a named list providing domains and data as given by gdxrrw::rgdx. This is a *workaround* to fix bugs in the implementation of gdxrrw::wgdx, namely the problems that domains are lost when writing the output of gdxrrw:rgdx and that for variables, a '_field' domain has always to be given. Using this wrapper, round-tripping data between R and gdx files should be possible.
raw2gdx(gdx, var)
raw2gdx(gdx, var)
gdx |
the gdx filename. |
var |
list of properties of a gdx symbol as provided by gdxrrw::rgdx. |
## Not run: # prepare raw data dt <- as.data.table(mtcars, keep.rownames = TRUE) writegdx("test.gdx", dt, "test_var", valcol="wt", uelcols="rn", type="parameter") # round-trip raw2gdx("test.gdx", gdxrrw::rgdx("test.gdx", list(name="test_var")) ## End(Not run)
## Not run: # prepare raw data dt <- as.data.table(mtcars, keep.rownames = TRUE) writegdx("test.gdx", dt, "test_var", valcol="wt", uelcols="rn", type="parameter") # round-trip raw2gdx("test.gdx", gdxrrw::rgdx("test.gdx", list(name="test_var")) ## End(Not run)
Read a variable, parameter or set from a gdx file to a data.table.
readgdx(fname, varname, field = NULL)
readgdx(fname, varname, field = NULL)
fname |
the gdx filename. |
varname |
name of the object to load. |
field |
(for variable), select a field (default="l"). |
a data.table
## Not run: dt <- as.data.table(mtcars, keep.rownames = TRUE) writegdx("test.gdx", dt, test_var, valcol="wt", uelcols="rn", type="parameter") new_dt <- readgdx("test.gdx", test_var, type="parameter") ## End(Not run)
## Not run: dt <- as.data.table(mtcars, keep.rownames = TRUE) writegdx("test.gdx", dt, test_var, valcol="wt", uelcols="rn", type="parameter") new_dt <- readgdx("test.gdx", test_var, type="parameter") ## End(Not run)
Save a data.table to a GAMS gdx file.
writegdx(gdx, dt, name, valcol, uelcols, type = "parameter", field = "l")
writegdx(gdx, dt, name, valcol, uelcols, type = "parameter", field = "l")
gdx |
the gdx filename. |
dt |
a data.table. |
name |
name of the variable. |
valcol |
name of data column. |
uelcols |
vector of column names with index dimensions. |
type |
type of symbol (variable or parameter) |
field |
the field if ‘type == ’variable'' |
## Not run: dt <- as.data.table(mtcars, keep.rownames = TRUE) writegdx("test.gdx", dt, "test_var", valcol="wt", uelcols="rn", type="parameter") ## End(Not run)
## Not run: dt <- as.data.table(mtcars, keep.rownames = TRUE) writegdx("test.gdx", dt, "test_var", valcol="wt", uelcols="rn", type="parameter") ## End(Not run)
Save a data.table to a parameter in a GAMS gdx file.
writegdx.parameter(gdx, dt, name, valcol, uelcols)
writegdx.parameter(gdx, dt, name, valcol, uelcols)
gdx |
the gdx filename. |
dt |
a data.table. |
name |
name of the parameter. |
valcol |
name of data column. |
uelcols |
vector of column names with index dimensions. |
## Not run: dt <- as.data.table(mtcars, keep.rownames = TRUE) writegdx.parameter(test_gdx, dt, test_var, valcol="wt", uelcols="rn") ## End(Not run)
## Not run: dt <- as.data.table(mtcars, keep.rownames = TRUE) writegdx.parameter(test_gdx, dt, test_var, valcol="wt", uelcols="rn") ## End(Not run)
Save a data.table to a variable in a GAMS gdx file.
writegdx.variable(gdx, dt, name, valcol, uelcols, field = "l")
writegdx.variable(gdx, dt, name, valcol, uelcols, field = "l")
gdx |
the gdx filename. |
dt |
a data.table. |
name |
name of the variable. |
valcol |
name of data column. |
uelcols |
vector of column names with index dimensions. |
field |
the field if ‘type == ’variable'' |
## Not run: dt <- as.data.table(mtcars, keep.rownames = TRUE) writegdx.variable(test_gdx, dt, test_var, valcol="wt", uelcols="rn") ## End(Not run)
## Not run: dt <- as.data.table(mtcars, keep.rownames = TRUE) writegdx.variable(test_gdx, dt, test_var, valcol="wt", uelcols="rn") ## End(Not run)