Hello,
I try to read a variable from a gdx file, write this variable to another gdx file and read it in again using the R bindings.
> var <- rgdx("fulldata.gdx", list(name="v35_shEsPeT"))
> str(var)
List of 11
$ name : chr "v35_shEsPeT"
$ type : chr "variable"
$ dim : int 3
$ val : num [1:256, 1:4] 22 22 22 22 22 22 22 22 22 22 ...
$ form : chr "sparse"
$ uels :List of 3
..$ : chr [1:40] "1900" "1905" "1910" "1915" ...
..$ : chr [1:11] "AFR" "CHN" "EUR" "IND" ...
..$ : chr [1:114] "ngcc" "ngccc" "ngt" "gastr" ...
$ domains : chr [1:3] "ttot" "all_regi" "all_te"
$ domInfo : chr "full"
$ field : chr "l"
$ varTypeText: chr "positive"
$ typeCode : int 3
> wgdx("test.gdx", var)
Error in wgdx("test.gdx", var) :
Inconsistent dimension found: 'dim'=3 doesn't match implied 'uels' dimension=2.
After some research, I figured the reason might be that only the level field of the variable is read, so I tried with the full variable.
> var <- rgdx("fulldata.gdx", list(name="v35_shEsPeT", field="all"))
> str(var)
List of 11
$ name : chr "v35_shEsPeT"
$ type : chr "variable"
$ dim : int 3
$ val : num [1:3135, 1:5] 22 22 22 22 22 22 22 22 22 22 ...
$ form : chr "sparse"
$ uels :List of 4
..$ : chr [1:40] "1900" "1905" "1910" "1915" ...
..$ : chr [1:11] "AFR" "CHN" "EUR" "IND" ...
..$ : chr [1:114] "ngcc" "ngccc" "ngt" "gastr" ...
..$ : chr [1:5] "l" "m" "lo" "up" ...
$ domains : chr [1:4] "ttot" "all_regi" "all_te" "_field"
$ domInfo : chr "full"
$ field : chr "all"
$ varTypeText: chr "positive"
$ typeCode : int 3
> wgdx("test.gdx", var)
> str(rgdx("test.gdx"))
List of 6
$ name: chr "*"
$ type: chr "set"
$ dim : int 1
$ val : NULL
$ form: NULL
$ uels: chr [1:165] "1900" "1905" "1910" "1915" ...
Now the writing procedure seems to be successful, however, reading the variable again seems to have changed its structure, i.e., the UEL dimensions are lost. As a next step I tried to provide name and field information to rgdx in the last step when re-reading the variable:
> str(rgdx("test.gdx", list(name="v35_shEsPeT", field="all")))
List of 11
$ name : chr "v35_shEsPeT"
$ type : chr "variable"
$ dim : int 3
$ val : num [1:3135, 1:5] 22 22 22 22 22 22 22 22 22 22 ...
$ form : chr "sparse"
$ uels :List of 4
..$ : chr [1:165] "1900" "1905" "1910" "1915" ...
..$ : chr [1:165] "1900" "1905" "1910" "1915" ...
..$ : chr [1:165] "1900" "1905" "1910" "1915" ...
..$ : chr [1:5] "l" "m" "lo" "up" ...
$ domains : chr [1:4] "ttot" "all_regi" "all_te" "_field"
$ domInfo : chr "relaxed"
$ field : chr "all"
$ varTypeText: chr "positive"
$ typeCode : int 3
Now all UEL dimensions contain all ranges. What am I missing here?
I’m using gams 25.1 on Ubuntu 18.04.1 LTS (gdxrrw_1.0.2)
Thanks for your help!