|
SOLUTIONS
|
RDataTypeRegister
registers a new Mathematica representation for a data type with name type.
DetailsDetails
- The type argument should normally be a string.
- Expressions matching the fwpatt pattern will be considered by RLink to be of type type.
- The rule fwrule instructs RLink how to convert the new Mathematica representation to representation based on RObject.
- The bckpatt pattern identifies types of expressions based on RObject that RLink considers to represent objects of type type.
- The rule bckrule instructs RLink how to convert such expressions to a more convenient, higher-level Mathematica representation defined with
. - If the type with the name type has already been registered,
returns $Failed.
ExamplesExamplesopen allclose all
Basic Examples (1)Basic Examples (1)
First load and install the R runtime:
| In[1]:= |
This will register a very simple data type (wrapper) that wraps around some core R data type, such as a vector:
| In[2]:= |
You can test that the definition is now effective by using ToRForm:
| In[3]:= |
| Out[3]= |
You can now send your data to R, using the custom data container just defined:
| In[4]:= |
| Out[4]= |
The result is automatically converted according to the inverse conversion rule used above in
, when returned back from R:
| In[5]:= |
| Out[5]= |
You can see that this will also work on derivative R objects obtained through manipulations with the original object that do not change its type (class in R):
| In[6]:= |
| Out[6]= |
You can now unregister the data type:
| In[7]:= |
Now the following will get back the usual representation based on RObject:
| In[8]:= |
| Out[8]= |
| In[9]:= |

