# InstallR on OS X with external R installation

How do I InstallR on OS X to use my already installed and configured R?

Simply using

InstallR["RHomeLocation" -> "/Library/Frameworks/R.framework/Resources"]


results in

$Failed InstallR::nopaclet: Could not find RLink runtime installed. Please use RLinkResourcesInstall to install it  How do I connect Mathematica to my installed R? Do I have to install a separate R for Mathematica? - Note: "/Library/Frameworks/R.framework/Resources" there is what R.home() reports. – raxacoricofallapatorius Mar 10 '14 at 13:42 @Szabolcs Sorry, I'm probably missing something. I followed all the instructions. My R version seems ok. But I have the following error: Needs::nocont: "Context "IGraphR was not created when Needs was evaluated." But IGraphR.m is in the right folder (the one opened by SystemOpen@FileNameJoin[{$UserBaseDirectory, "Applications"}]) –  sam84 Apr 8 '14 at 8:20
@sam84 If IGraphR.m is really in the right folder, and you get this message, then you don't have the correct IGraphR.m file. Try downloading it again from here –  Szabolcs Apr 8 '14 at 13:54
@Szabolcs yes, now it works. Thanks! –  sam84 Apr 9 '14 at 7:06

Try like this in a fresh kernel:

Needs["RLink"]

SetEnvironment["DYLD_LIBRARY_PATH" -> "/Library/Frameworks/R.framework/Resources/lib"];

InstallR["RHomeLocation" -> "/Library/Frameworks/R.framework/Resources"];


Update: With Mathematica 10.0.1 (but not 10.0.0), use

InstallR["RHomeLocation" -> "/Library/Frameworks/R.framework/Resources", "RVersion" -> 3]; (* for M 10.0.1 *)


This works if you are using the R distribution from http://www.r-project.org/, but if I recall correctly some people said it didn't work with some other R distributions (e.g. MacPorts's R). I only tried with the official R.

To check that you are indeed running with the chosen version of R, evaluate

REvaluate["R.version.string"]


which on my system returns {"R version 3.0.3 (2014-03-06)"} (as I have R 3.0.3).

I described this before here.

Note: With Mathematica 9.0.1 it is necessary to first make sure that RLink is set up and working with Mathematica's internal R distribution, as described in the user guide. Once that is done, an external R can be used as above. Otherwise InstallR might exit with an InstallR::nopaclet error.

-
I still get "InstallR::nopaclet: Could not find RLink runtime installed. Please use RLinkResourcesInstall to install it". (I am using the r-project distribution.) –  raxacoricofallapatorius Mar 10 '14 at 13:49
You must install Mathematica's internal R first. Once that it working, you can use an external R like above. See my update. I assume this will install not only the internal R, but also some other code that's necessary for RLink to work. –  Szabolcs Mar 10 '14 at 13:52
@raxacoricofallapatorius RLinkResourcesInstall uses the same paclet mechanism that is used e.g. for downloading the curated built-in data from Wolfram servers. This is not something external, it is part of the general strategy Mathematica uses to download its optional parts, or parts which change in time (such as data). The resulting paclet is installed into a special Paclets subdirectory inside \$UserBaseDirectory, where also other packets are installed (mostly, data). The Java part of RLink comes as a part of the core RLink distro, which is a part of Mathematica distribution. –  Leonid Shifrin Mar 10 '14 at 14:57
@raxacoricofallapatorius Ok, I looked into the code, and I can see where this bug is coming from. Basically, indeed, the internal R distro is currently required to be installed, even when this is not strictly necessary. So, for now, it is probably easiest to just install the internal version. If you are very much against that, I could write a patch to bypass this and post it here in a comment, but it will be untested (no time now to test it), and things may get wrong in more than one place in such patch. –  Leonid Shifrin Mar 10 '14 at 15:30
@raxacoricofallapatorius No problem. Also, I feel sorry that RLink's current state prevents you and some others from using it in the way you'd like to. I do hope to have some dedicated time to improve it some time soon. –  Leonid Shifrin Mar 10 '14 at 17:12