RSet


assigns the value of the Wolfram Language expression expr to a variable var in the R workspace, returning back the value of expr upon success and $Failed upon failure.

DetailsDetails

  • Use to send Wolfram Language expressions to R.
  • The variable name var must be a string, but is not restricted to be the name of a valid R variable. It can actually be any piece of R code, which represents a legal lhs for the purposes of assignments in R (it is an L-value).
  • The expression expr must be of the type convertible to R. Normally, you can use the ToRForm function to obtain an internal RLink representation for Wolfram Language expressions you want to send to R, and at the same time test whether or not your expression is legal.
  • works with both the short and long (internal) forms of the expression expr. The form of an expression that is returned is the same as the one used for expr.

ExamplesExamplesopen allclose all

Basic Examples  (5)Basic Examples  (5)

In[1]:=
Click for copyable input

Send a single number to R:

In[1]:=
Click for copyable input
Out[1]=

Now send a vector:

In[2]:=
Click for copyable input
Out[2]=

Add these in R:

In[3]:=
Click for copyable input
Out[3]=

Change the dimensions of the vector v in R:

In[1]:=
Click for copyable input
Out[1]=

Now v becomes a matrix:

In[2]:=
Click for copyable input
Out[2]=

Send another matrix to R:

In[3]:=
Click for copyable input
Out[3]=

Compute a matrix product in R:

In[4]:=
Click for copyable input
Out[4]=

Do the same in the Wolfram Language:

In[5]:=
Click for copyable input
Out[5]=

Send a nested list to R (which will be stored as an R list):

In[1]:=
Click for copyable input
Out[1]=

Test the type of R lst variable:

In[2]:=
Click for copyable input
Out[2]=

Assign a different expression to the first part of the list:

In[3]:=
Click for copyable input
Out[3]=

Test:

In[4]:=
Click for copyable input
Out[4]=

Sending an expression that cannot be converted to one of the R types fails:

In[1]:=
Click for copyable input
Out[1]=

You can see that also by using ToRForm:

In[2]:=
Click for copyable input
Out[2]=