R API (rmessageix)

Support for message_ix and ixmp in R are provided through reticulate, a package that allows nearly seamless access to the Python API.

See Installation for instructions on installing the rmessageix R package. Once installed, load the package:

library(rmessageix)

This creates two global variables, ixmp and message_ix, that can be used much like the Python modules:

mp <- ixmp$Platform(name = "default")
scen <- message_ix$Scenario(mp, "model name", "scenario name")
# etc.

See the R versions of the Austria tutorials for full model examples using rmessageix.

Some tips:

  • As shown above, R uses the $ character instead of . to access methods and properties of objects. Where Python code examples show, for instance, scen.add_par(...), R code should use scen$add_par(...).

  • MESSAGEix model parameters with dimensions indexed by the year set (e.g. dimensions named year_act or year_vtg) must be indexed by integers; but R treats numeric literals as floating point values. Therefore, instead of:

    ya1 = 2010
    ya2 = c(2020, 2030, 2040)
    ya3 = seq(2050, 2100, 10)
    
    # ...store parameter data using year_act = ya1, ya2, or ya3
    

    …use as.integer() to convert:

    ya1 = as.integer(2010)
    ya2 = sapply(c(2020, 2030, 2040), as.integer)
    ya3 = as.integer(seq(2050, 2100, 10))