readGDX: readGDX

View source: R/readGDX.R

readGDXR Documentation

readGDX

Description

Function to read gdx files in R. It is partly a reimplementation of readGDX which is now based on magclass structures rather than array structures.

Usage

readGDX(
  gdx,
  ...,
  types = c("sets", "equations", "parameters", "variables", "aliases"),
  field = "All",
  format = "simplest",
  restore_zeros = TRUE,
  react = "warning",
  spatial = NULL,
  temporal = NULL,
  select = NULL,
  collapseNames = TRUE,
  magpie_cells = TRUE
)

Arguments

gdx

Either file name of a gdx file or an already read in gdx (in the latter case readGDX just acts as a filter. This can be useful if you want to apply several functions on the same gdx file. In that case you could read in the gdx first and then filter the data you need using readGDX.)

...

search strings defining the objects that should be read from gdx file, with *-autocompletion. Can also be vectors containing more than one search strings

types

Types of objects that should be extracted. Available options are "sets", "equations", "parameters", "variables" and "aliases".

field

Defining what kind of information should be returned. "All" means all available data. Other options are "l" (level value), "m" (marginal), "lo" (lower bound), "up" (upper bound) and "s" (scaling factor). In the case that the level value is not part of the field value (all options other than "All" and "l") only data for equations and variables are returned as all other types do not have this kind of information. WARNING: field has to be set to "All" if the data is planned to be written back to a GDX. Otherwise writeGDX will not work!

format

Output format. Five choices are currently available detailed, simple, simplest, raw and first_found. Instead of writing the full format name each format has its own abbreviation as shown below.

list("detailed")

This is the old default which returns a list of lists separating the outputs first in type and afterwards in variable names.

(d)

This is the old default which returns a list of lists separating the outputs first in type and afterwards in variable names.

list("simple")

This returns a list of outputs.

(s)

This returns a list of outputs.

list("simplest")

Behaves like "simple" if more than one object is returned. However, if only one object is read from gdx file the magpie object itself is returned getting rid of the surrounding list structure. This is the recommended format for interactive use.

(st - default setting)

Behaves like "simple" if more than one object is returned. However, if only one object is read from gdx file the magpie object itself is returned getting rid of the surrounding list structure. This is the recommended format for interactive use.

list("raw")

This returnes the data as it comes from rgdx. This is especially useful the data should be written again to a gdx file without having much transformations in between.

(r)

This returnes the data as it comes from rgdx. This is especially useful the data should be written again to a gdx file without having much transformations in between.

list("first_found")

This is a special format for the case that you would like to read in exactly one object but you do not know exactly what the name of the object is. Here, you can list all possible names of the object and the function will return the first object of the list which is found. This is especially useful writing read functions for gdx outputs of models in which the names of a data object might change over time but the function itself should work for all model versions. Having this format helps to make your gdx-based functions backwards compatible to older versions of a gdx file with different naming.

(f)

This is a special format for the case that you would like to read in exactly one object but you do not know exactly what the name of the object is. Here, you can list all possible names of the object and the function will return the first object of the list which is found. This is especially useful writing read functions for gdx outputs of models in which the names of a data object might change over time but the function itself should work for all model versions. Having this format helps to make your gdx-based functions backwards compatible to older versions of a gdx file with different naming.

list("name")

In this case the function returns the name of all objects found in the gdx which fit to the given search pattern and the given type as vector.

(n)

In this case the function returns the name of all objects found in the gdx which fit to the given search pattern and the given type as vector.

restore_zeros

Defines whether 0s, which are typically not stored in a gdx file, should be restored or ignored in the output. By default they will be restored. If possible, it is recommended to use restore_zeros=TRUE. It is faster but more memory consuming. If you get memory errors you should use restore_zeros=FALSE

react

determines the reaction, when the object you would like to read in does not exist. Available options are "warning" (NULL is returned and a warning is send that the object is missing), "silent" (NULL is returned, but no warning is given) and "error" (The function throws out an error)

spatial

argument to determine the spatial columns in the dataframe to be converted to a magclass object. Defaults to NULL. See as.magpie for more information.

temporal

argument to determine the temporal columns in the dataframe to be converted to a magclass object. Defaults to NULL. See as.magpie for more information.

select

preselection of subsets in the data coming from the gdx using the function mselect. Information has to be provided as a list of selections (e.g. select=list(type="level")). See mselect for more information.

collapseNames

Boolean which determines whether collapseNames should be applied in mselect or not.

magpie_cells

(boolean) determines whether a set "j" gets special treatment by replacing underscores in the set elements with dots. Active by default for historical reasons. Can be ignored in most cases. Makes only a difference, if 1) GDX element depends on set "j", 2) set "j" contains underscores.

Value

The gdx objects read in the format set with the argument format.

Author(s)

Jan Philipp Dietrich

See Also

writeGDX, mselect

Examples

## Not run: 
readGDX("bla.gdx", "blub*")

## End(Not run)


pik-piam/gdx documentation built on March 12, 2024, 10:30 a.m.