Learn R Programming

magclass (version 3.74)

magpie-class: Class "magpie" ~~~

Description

The MAgPIE class is a data format for cellular MAgPIE data with a close relationship to the array data format. is.magpie tests if x is an MAgPIE-object, as.magpie transforms x to an MAgPIE-object (if possible).

Usage

is.magpie(x) as.magpie(x,...)

Arguments

x
An object that should be either tested or transformed as/to an MAgPIE-object.
...
additional arguments supplied for the conversion to a MAgPIE object. Allowed arguments for arrays and dataframes are spatial and temporal both expecting a vector of dimension or column numbers which contain the spatial or temporal information. By default both arguments are set to NULL which means that the as.magpie will try to detect automatically the temporal and spatial dimensions. The arguments will just overwrite the automatic detection. If you want to specify that the data does not contain a spatial or temporal dimension you can set the corresponding argument to 0. In addition as.magpie for data.frames is also expecting an argument called datacol which expects a number stating which is the first column containing data. This argument should be used if the dimensions are not detected corretly, e.g. if the last dimension column contains years which are then detected as values and therefore interpreted as first data column. In addition an argument tidy=TRUE can be used to indicate that the data.frame structure is following the rules of tidy data (last column is the data column all other columns contain dimension information). This information will help the conversion.

Objects from the Class

Objects can be created by calls of the form new("magpie", data, dim, dimnames, ...). MAgPIE objects have three dimensions (cells,years,datatype) and the dimensionnames of the first dimension have the structure "REGION.cellnumber". MAgPIE-objects behave the same like array-objects with 2 exceptions: 1.Dimensions of the object will not collapse (e.g. x[1,1,1] will remain 3D instead of becoming 1D) 2.It is possible to extract full regions just by typing x["REGIONNAME",,]. Please mind following standards: Header must not contain any purely numeric entries, but combinations of characters and numbers are allowed (e.g. "bla","12" is forbidden, wheras "bla","b12" is allowed) Years always have the structure "y" + 4-digit number, e.g. "y1995" Regions always have the structure 3 capital letters, e.g. "AFR" or "GLO" This standards are necessary to allow the scripts to detect headers, years and regions properly and to have a distinction to other data.

Slots

.Data:
Object of class "array" ~~

Extends

Class "array", from data part. Class "structure", by class "array", distance 2. Class "matrix", by class "array", distance 2, with explicit test and coerce. Class "vector", by class "array", distance 3, with explicit coerce. Class "vector", by class "array", distance 5, with explicit test and coerce.

Methods

[
signature(x = "magpie"): An extended []-syntax preventing the collapsing of the array to less than 3 dimenions and allowing the direct access of regions by typing x["REGIONNAME",,]. In addition drop=TRUE will collapse the dimension within the 3 main categories, pmatch will allow for partial matches accessing the data (pmatch=TRUE will apply a general partial match, pmatch="left" will apply a partial match where the matching has to be at the beginning and for pmatch="right" the match has to be at the end of the string) and invert=TRUE will return the inverse subset of your query.
Obs
signature(e1 = "magpie", e2 = "magpie"): This method allows to use basic arithmetic calculations such as + or * with MAgPIE objects.

See Also

read.magpie, write.magpie, getRegions, getYears, getNames, getCPR, ncells, nyears, ndata

Examples

Run this code
showClass("magpie")

data(population_magpie)

# returning PAO and PAS for 2025
population_magpie["PA",2025,,pmatch="left"]

# returning CPA for 2025
population_magpie["PA",2025,,pmatch="right"]

# returning CPA PAO and PAS for 2025
population_magpie["PA",2025,,pmatch=TRUE]

# returning PAS and 2025
population_magpie["PAS",2025,]

# returning everything but values for PAS or values for 2025
population_magpie["PAS",2025,,invert=TRUE]


Run the code above in your browser using DataLab