How do I connect an R installation to my Wolfram product?
R is a programming language and software environment for statistical computing. RLink is the included Wolfram Language package to connect R with your Wolfram product, using JLink and RJava/JRI libraries. It allows you to exchange data between the Wolfram Language and R, as well as to evaluate R code from within the Wolfram Language.
To connect R with the Wolfram Language, a few additional setup steps are required. Note that Wolfram products based on Wolfram Language 13.0 only work with R versions up to 3.6.3.
- Make sure your machine has a recent JDK (Java development kit).
- If R is not yet installed on your machine, download its version 3.6.3 from a trusted location and install it.
- If on Windows, set the environment variable JAVA_HOME to the location of your JDK for your current R session:
- Go to your System Properties window by opening your Start Menu, searching for “environment variables” and selecting “Edit the system environment variables”.
- On the Advanced tab, select Environment Variables and add or edit the JAVA_HOME variable to point to your JDK location.
By default, the JDK location isC:\Program Files\Java\jdk-11.0.8\bin
.
- Start your R distribution’s interactive console.
- In the console, install the rJava library:
> install.packages('rJava')
- Look up and note down the location of the installed rJava and JRI libraries of your R installation:
> .libPaths()
On Windows, these typically read:
[1] "C:/Users/Wolfram/Documents/R/win-library/3.6" "C:/Program Files/R/R-3.6.3/library"
On macOS:
[1] "/Library/Frameworks/R.framework/Versions/3.6/Resources/library"
On Linux:
[1] "/usr/lib64/R/library" "/usr/share/R/library"
- In your Wolfram program, evaluate the following inputs to install R.
On Windows, if the paths you noted down in the previous step are
"C:/Users/Wolfram/Documents/R/win-library/3.6", "C:/Program Files/R/R-3.6.3/library"
:In[1]:= JLink`UninstallJava[] In[2]:= Needs["RLink`"] In[3]:= InstallR["RVersion" -> "3.6.3", "RHomeLocation" -> "C:/Program Files/R/R-3.6.3/", "JRINativeLibraryLocation" -> "C:/Users/Wolfram/Documents/R/win-library/3.6/rJava/jri/x64"]
On macOS, if the path you noted down in the previous step is
"/Library/Frameworks/R.framework/Versions/3.6/Resources/library"
:In[1]:= JLink`UninstallJava[] In[2]:= Needs["RLink`"] In[3]:= InstallR["RVersion" -> "3.6.3", "RHomeLocation" -> "/Library/Frameworks/R.framework/Versions/3.6/Resources", "JRINativeLibraryLocation" -> "/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/jri"]
On Linux, if the paths you noted down in the previous step are
"/usr/lib64/R/library", "/usr/share/R/library"
:In[1]:= JLink`UninstallJava[] In[2]:= Needs["RLink`"] In[3]:= InstallR["RVersion" -> "3.6.3", "RHomeLocation" -> "/usr/lib64/R/library/Frameworks/R.framework/Versions/3.6/Resources", "JRINativeLibraryLocation" -> "/usr/share/R/library/rJava/jri"]
- Evaluate the following examples to verify the R installation was successful:
In[4]:= REvaluate["R.Version()"] Out[4]= RObject[{{"x86_64-w64-mingw32"}, {"x86_64"}, {"mingw32"}, {"x86_64, mingw32"}, {""}, {"3"}, {"6.1"}, {"2019"}, {"07"}, {"05"}, {"76782"}, {"R"}, {"R version 3.6.3 (2019-07-05)"}, {"Action of the Toes"}}, RAttributes["names" :> {"platform", "arch", "os", "system", "status", "major", "minor", "year", "month", "day", "svn rev", "language", "version.string", "nickname"}]]
In[5]:= REvaluate["1:10"] Out[5]= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Contact Support
Whether you have a question about billing, activation or something more technical, we are ready to help you.
1-800-WOLFRAM (+1-217-398-0700 for international callers)
Customer Support
Monday–Friday
8am–5pm US Central Time
- Product registration or activation
- Pre-sales information and ordering
- Help with installation and first launch
Advanced Technical Support (for eligible customers)
Monday–Thursday
8am–5pm US Central Time
Friday
8:30–10am & 11am–5pm US Central Time
- Priority technical support
- Product assistance from Wolfram experts
- Help with Wolfram Language programming
- Advanced installation support