# Using a different R version with RLink

I wish to use a different version of R than what is provided by Mathematica 9. For example, I want to use the Macports version of R, where R_HOME is /opt/local/lib/R.

When I type:

Needs["RLink"]
InstallR["RHomeLocation" -> "/opt/local/lib/R"]


I get the error:

InstallR::fail: Failed to install R.
The following error was encountered: Unable to load dynamic libraries >>


(I tried to doctor up my ~/.MacOSX/environment.plist with DYLD_LIBRARY_PATH, but no luck.)

-
I'm also wondering if it is (will) be possible to update the internal R that gets downloaded from WRI to a later version (currently it's 2.14 while the latest R is 2.15). Once we install it using InstallR[]`, are we stuck with a particular version? – Szabolcs Nov 29 '12 at 3:23
Originally I hoped that this option would work on all platforms. My initial tests indicated that it did. I had to then narrow this down to Windows for the time being, since problems on Linux and Mac were detected. This is a high-priority issue for RLink, so I hope to have more to say soon enough. – Leonid Shifrin Nov 29 '12 at 9:28
@Szabolcs Yes, the users are stuck with that version until we update the paclets. But I hope that the option of using own version of R will be working on other (than Windows) platforms reasonably soon, which should mitigate this situation. – Leonid Shifrin Nov 29 '12 at 12:08
For Linux folks: at least on some flavors of Linux, it has been reported that RLink works fine with the stand-alone R distribution. – Leonid Shifrin Nov 29 '12 at 17:45

The documentation says, and I quote,

Using Your Own R Distribution (Windows only)

On Windows, it is currently possible for you to use your own R distribution with RLink, which may have a number of advantages in certain circumstances. For example, you already have a customized R distribution that you would like to continue using for everything, including work with Mathematica/*RLink*. Or, you would like to install extra packages.

So, this might be possible on Windows but not on other systems.

-
I would almost think that it would be easier under Mac/Linux. Meh. – Eric Brown Nov 29 '12 at 1:46
@OleksandrR. Oh no, if only you knew how much time was spent to actually make this work for the R version that comes with RLink, on Linux and Mac - this took the majority of time for RLink development. I was of course building R on both Linux and Mac from sources, and doing a whole lot more to make the default R coming with RLink work without setting any env. variables. For external versions of R, it was just unfortunate that some problems with this were detected late in the develpoment, so I had no time to fix that and had to restrict this to Windows only, for the time being. – Leonid Shifrin Nov 29 '12 at 9:33
@LeonidShifrin sorry to hear that; it sounds like you had a really bad time with this! Good that you persisted, though--this seems to be the first time that WRI has really even officially acknowledged the existence of what could be seen as a competitor, let alone building comprehensive support for it into Mathematica. A major achievement on your part! – Oleksandr R. Dec 1 '12 at 19:31
@OleksandrR. Thanks! Re: bad times - one of the problems for me was that as a programmer, I am self-taught, and most of my life I was doing math / physics which did not involve any coding at all. So, some things which people with the proper CS / coding background would know or sort out quite fast, were taking me long to get resolved. But, I am getting better (I hope :)). Re: competition ackowledgement by WRI - well, I made my position on that clear to other people involved in M/R relationship assessment, but whether this had any impact on the final decision in that direction, I have no idea. – Leonid Shifrin Dec 1 '12 at 20:31