magclass (version 4.107.0)

read.magpie: Read MAgPIE-object from file

Description

Reads a MAgPIE-file and converts it to a 3D array of the structure (cells,years,datacolumn)

Usage

read.magpie(file_name, file_folder = "", file_type = NULL,
  as.array = FALSE, old_format = FALSE, comment.char = "*",
  check.names = FALSE)

Arguments

file_name

file name including file ending (wildcards are supported). Optionally also the full path can be specified here (instead of splitting it to file\_name and file\_folder)

file_folder

folder the file is located in (alternatively you can also specify the full path in file\_name - wildcards are supported)

file_type

format the data is stored in. Currently 12 formats are available: "rds" (recommended compressed format), "cs2" (cellular standard MAgPIE format), "csv" (regional standard MAgPIE format), "cs3" (multidimensional format compatible to GAMS), "cs4" (alternative multidimensional format compatible to GAMS, in contrast to cs3 it can also handle sparse data), "csvr", "cs2r", "cs3r" and "cs4r" which are the same formats as the previous mentioned ones with the only difference that they have a REMIND compatible format, "m" (binary MAgPIE format "magpie"), "mz" (compressed binary MAgPIE format "magpie zipped") "put" (format used primarily for the REMIND-MAgPIE coupling) and "asc", (ASCII-Grid format as used by ArcGis) . If file\_type=NULL the file ending of the file\_name is used as format. If format is different to the formats mentioned standard MAgPIE format is assumed.

as.array

Should the input be transformed to an array? This can be useful for regional or global inputs, but all advantages of the magpie-class are lost.

old_format

used to read files in old MAgPIE-format (unused space was not located at the beginning of the file), will be removed soon.

comment.char

character: a character vector of length one containing a single character or an empty string. Use "" to turn off the interpretation of comments altogether. If a comment is found it will be stored in attr(,"comment"). In text files the comment has to be at the beginning of the file in order to be recognized by read.magpie.

check.names

logical. If TRUE then the names of the variables in the data frame are checked to ensure that they are syntactically valid variable names. Same functionality as in read.table.

Value

x

MAgPIE-object

Details

This function reads from 12 different MAgPIE file\_types. "rds" is a R-default format for storing R objects."cs2" is the new standard format for cellular data with or without header and the first columns (year,regiospatial) or only (regiospatial), "csv" is the standard format for regional data with or without header and the first columns (year,region,cellnumber) or only (region,cellnumber). "cs3" is a format similar to csv and cs2, but with the difference that it supports multidimensional data in a format which can be read by GAMS, "put" is a newly supported format which is mosty used for the REMIND-MAgPIE coupling. This format is only partly supported at the moment. "asc" is the AsciiGrid format (for example used for Arc Gis data). "nc" is the netCDF format (only "nc" files written by write.magpie can be read). All these variants are read without further specification. "magpie" (.m) and "magpie zipped" (.mz) are new formats developed to allow a less storage intensive management of MAgPIE-data. The only difference between both formats is that .mz is gzipped whereas .m is not compressed. So .mz needs less memory, whereas .m might have a higher compatibility to other languages. Since library version 1.4 read.magpie can also read regional or global MAgPIE csv-files.

See Also

"'>magpie", write.magpie

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
a <- read.magpie("lpj_yield_ir.csv")
write.magpie(a,"lpj_yield_ir.mz")
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab