"R" (External Evaluation System)

Details

  • R is a language and environment for statistical computing and graphics.
  • ExternalEvaluate with R works via RLink, and no further configuration is needed if RLink is functioning.

ExternalEvaluate Usage

  • ExternalEvaluate["R",code] executes the code string in R and returns the result as a Wolfram Language expression.

Data Types

  • The following R built-in types are supported:
  • logicalTrue | FalseBoolean True/False values
    integerIntegerinteger
    doubleRealreal number
    complexComplexcomplex number
    characterStringstring of characters
    arrayListlist of objects
    vectorListlist of objects with the same data type
    listListlist of objects of different types
    matrixListmultidimensional list
    data frameRDataFrameRLink data type
    NAMissingmissing value

Usage Notes

  • All calls to R run in a single R session, whether they are executed via ExternalEvaluate or via an external language cell.
  • The R session used is the same one used by RLink, so you can interleave calls using RLink functions with calls using ExternalEvaluate.

Examples

open allclose all

Basic Examples  (3)

When scalars are entered, they are automatically considered vectors of length 1 by R:

R lists are returned as Wolfram Language lists:

Type > and select R from the drop-down menu to get a code cell that uses ExternalEvaluate to evaluate:

seq(0,pi,by=0.2)

Scope  (5)

Evaluate a Boolean expression:

In R, numbers are of type double by default:

You can force a number to be an integer by appending L:

R objects are returned as RLink RObject expressions:

R functions are returned as RLink RFunction expressions:

You can mix calls to the same R session using ExternalEvaluate and RLink functions: