GAMS-dev / transfer-r

gamstransfer: data exchange between GAMS and R
2 stars 0 forks source link

readGDX( ) silently drops domain sets with the same name as a field when reading variables (probably equations, too) #1

Open 0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q opened 2 months ago

0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q commented 2 months ago

Minimal working example:

Sets
  something / foo, bar /
  level     / foo, bar /
;

Variables foo(level), bar(something);

foo.l(level)     = 1;
bar.l(something) = 1;

Execute_Unload 'foo.gdx', foo, bar;
lapply(readGDX('foo.gdx', c('foo', 'bar')), getElement, name = 'records')
# $foo
#   level marginal lower upper scale
# 1     1        0  -Inf   Inf     1
# 2     1        0  -Inf   Inf     1
# 
# $bar
#   something level marginal lower upper scale
# 1       foo     1        0  -Inf   Inf     1
# 2       bar     1        0  -Inf   Inf     1

The level set name collides with the level column of the variable, disappearing.

abhosekar commented 2 months ago

Thanks for reporting. gamstransfer does not change the user supplied records data.frame as much as possible. This is a corner case where the keyword level clashes with the column name in the supplied records. This is a bug.

Note that readGDX and writeGDX are still undocumented functions that I don't recommend the users to use just yet. This is being developed to read GDX files with many symbols where the small amount of time to create a symbol object is a bottleneck. This is not usual but can happen in some cases. A typical example is a scalar GDX files. One should use the documented steps of creating a container and using the container method read.

m = Container$new()
m$read("foo.gdx")

The bug is independent of this method. I will notify as soon as the bug gets fixed. Thanks.