Message Boards Message Boards

2
|
7994 Views
|
6 Replies
|
11 Total Likes
View groups...
Share
Share this post:

RLink on a silicon Mac?

I tried using RLink today on a new silicon Mac. The silicon (ARM) version of R is installed and works. When I run InstallR[] I get the following cryptic error message. "InstallR::bndlunsupp: RLink does not support bundled R runtime for the current platform. Please use externally installed R distribution"

Ok. How?? I've looked at the RLink documentation and it discusses a "TargetPlatform" option, but it is not a model of clarity and does not provide examples.

POSTED BY: Seth Chandler
6 Replies

Seth,

the recipe of John (kudos to him for posting it) was possible because I actually took care of incorporating the workaround from my previous recipe into the system for 13.0.1. But since this apparently did not work for you and I could not re-test things properly at that moment, I just admitted about the generally less than stellar situation with external R connectivity, particularly the documentation is behind. Perhaps I should've suggested you to try this simplified procedure.

I agree with you that we should try make things more automated. We've run some experiments to automate the JRI library building step at run-time, hopefully the setup will be simplified in the future.

Regarding package installation, we may add a dedicated RPackageInstall (or similarly named) function in 13.2. There are technical reasons why package installation from within RLink with REvaluate fails. Basically, R interactively prompts to pick a mirror, but RLink has not been built with the ability to process such inverse interactive prompts / requests from R.

In the mean time, one could use something like this:

Options[installRPackage] = { "MirrorURL" -> "http://cran.us.r-project.org" }
installRPackage[name_String, OptionsPattern[]] := REvaluate[
    "install.packages('"<> name <>"', repos='" <> OptionValue["MirrorURL"] <> "')"
]

which normally should work.

POSTED BY: Leonid Shifrin

OMG. It works! Thanks. I still would like for it to be automated in future versions of Mathematica.

One thing I learned, however.. Suppose one wants to use an R package such as "dagitty" (causal inference). When I tried install.packages("dagitty") from inside the Mathematica notebook, I got an R crash that required me to run InstallR again. So I then hopped over to the R console and ran install.packages("dagitty") there. I then ran library(dagitty) inside the Mathematica notebook. Success. I now appear able to use dagitty functionality.

Of course, all this would be easier, if Wolfram built a first-class causal inference package that could find adjustment sets, conditional independencies, determine d-separation. It along with Bayesian methods are sorely missing from the current version. Maybe 13.2? 14? Please.

But let not the main point be obscured. Thanks, John Snyder, for an easier recipe to get R running within a Mathematica notebook on a Silicon Mac.

POSTED BY: Seth Chandler
Posted 2 years ago

Seth,

I got it working on my new Mac Studio as follows:
1) Uninstall the R consul, if you have one, by dragging it from your Applications folder to Trash.
2) Download the latest R-4.2.0-arm64.pkg from the cran.r-project.org.
3) Double click on the arm64.pkg and install it normally in your Applications folder.
4) Start the R consul from your Applications folder and execute install.packages("rJava")
5) Open a new Mathematica notebook and execute the following code:

Needs["RLink`"];
JLink`UninstallJava[];
InstallR["RHomeLocation"->"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources","RVersion"->"4.2.0"]

6) To check that all is working correctly execute from Mathematica:REvaluate["R.version.string"]

Step 6 should return {R version 4.2.0 (2022-04-22)} and you're good to go.

POSTED BY: John Snyder

Seth, you are right, and this is my oversight. That work has been mostly done. I will try to complete this for either 13.1 or 13.1.1. I am sorry for the inconvenience.

POSTED BY: Leonid Shifrin

I appreciate the instructions. From what I can see, however, the problem was not fixed for Version 13. I still get the error message on my Silicon Mac when I try to run R. Given the large number of people now running Silicon Macs and the virtues of having simple R connectivity, I would hope that the fix can be automated very soon in a way consistent with the usability aspirations of Wolfram Language. Your instructions, while I am sure the very best that are possible, are sufficiently complex that they pretty much defeat the point of RLink altogether.

POSTED BY: Seth Chandler

Hi Seth,

I wasn't aware of your question until today, otherwise would've posted this answer earlier. It does generally make sense to cross-post questions to Mathematica at Stack Exchange, since some people (myself included) monitor that venue more frequently than the Community.

I have lost the battle with online editor here to make a minimally nicely formatted reply, so I will instead attach a text file with instructions, to this post. The notes in that file will be the basis for part of the RLink documentation for V13, for using external R versions with RLink. The workaround given in the notes, used for launching InstallR[] on Mac ARM, will also be removed / made internal, so that the user will not have to do it manually. However, some portion of the instructions (in the "one time configuration steps" section) will generally be always necessary for bleeding edge versions of R, since RLink's R library support usually lags somewhat behind.

If something in those instructions does not work for you, please let me know.

Attachments:
POSTED BY: Leonid Shifrin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract