evaluates a string of R code, and returns the result as a Wolfram Language expression.
- The code code must be a string of valid R code, which, after execution, produces the result of one of the types that can be handled by REvaluate.
- These are the R types explicitly supported by RLink, elements of which can be returned by REvaluate, along with the internal RLink heads of expressions representing such elements:
"integer" RVector "double" RVector "complex" RVector "logical" RVector "character" RVector "list" RList "NULL" RNull "closure" RFunction "builtin" RFunction "environment" REnvironment
- Apart from explicitly supported types, most other types can be imported from R into the Wolfram Language by converting them into a string (deparsed R code). Such elements are wrapped into an RCode wrapper.
- The type "environment" is only partially supported at present. Namely, it will consider all environment objects explicitly exported from R into the Wolfram Language to represent global environments.
- When the code passed to REvaluate evaluates to a type not handled by REvaluate, REvaluate returns $Failed.
Examplesopen all close all
Basic Examples (12)
To suppress the output, or when no output is needed, put a semicolon at the end of the R code, in which case REvaluate returns Null:
This is the same, but using explicit function mapping (sapply in R corresponds to Map in the Wolfram Language):
This is a slightly more complex example. Here, a function is mapped that takes a value of the independent variable and returns it back together with the value of the function (here, sine) wrapped in a vector:
You can see that the result is an R list and has a non-empty attribute set (attribute names); therefore, it is represented as a general R object with a head RObject. This topic is covered in more details in "R Data Types in RLink" and the RObject reference page.