RInterface package
Table of Contents
1. What is R?
R is a platform for statistical computing (https://www.r-project.org/). Algebraic statisticians may be interested in using both R and Macaulay2! Or algebraic geometers who teach a lot of undergraduate probability/statistics… :)
pnorm(1.96, lower.tail=FALSE)
There's already a library for running Macaulay2 code inside R:
citation("m2r")
library(m2r) m2("R = QQ[x,y,z,w]") m2("monomialCurveIdeal(R, {1, 2, 3})")
2. What is RInterface?
RInterface is a new Macaulay2 package that goes in the opposite direction, i.e., it allows us to run R code inside Macaulay2.
needsPackage "RInterface"; pnorm = RFunction "pnorm" value pnorm(1.96, "lower.tail" => false)
2.1. RObject
The basic type is RObject, which can be converted to a Macaulay2 object with "value". Lots of methods are defined for RObjects.
needsPackage "RInterface"; RObject {1, 3/2, pi, ii} value oo 2 + RObject 3 cos RObject pi methods RObject
2.2. RFunction
Another type is RFunction, which wraps around an R function. It converts its inputs into the appropriate RObject.
needsPackage "RInterface"; qnorm = RFunction "qnorm" qnorm \ {0.95, 0.975, 0.995} ancestors class qnorm
2.3. RSymbol
RFunction's are constructed using RSymbol, which is a method that creates RObject's from symbol names. It is also useful for loading data sets.
needsPackage "RInterface"; RSymbol "iris" value oo
3. How does it work?
Under the hood, RInterface uses the ForeignFunctions package to make calls to the R C API.
needsPackage "RInterface"; ancestors RObject code (NewFromMethod, RFunction, RObject) debug RInterface class \ {PROTECT, lcons, UNPROTECT}