24
$\begingroup$

How can I use RLink with R 3.5 (the latest version) on macOS?

I believe that Mathematica has huge potential as a glue language, and that links to other systems, like RLink, are not only very useful, but essential. Sadly, RLink was never fully finished, despite what Wolfram marketing might tell you. RLink is simply useless without the ability to connect to an external R installation into which packages can be installed. This ability was never officially supported on macOS.

There were workarounds though, and I set up a webpage that described them. But as new RLink and macOS versions were released, the workarounds became more complicated and using RLink more difficult. Originally it was enough to point RLink to a different R installation. Later, it needed to be patched to use the correct shared libraries. After that, its runtime started crashing on first use, and would only work on the second try. Wolfram was notified of all these problems, but still didn't dedicate RLink the resources necessary to fix this.

Now with R 3.5, RLink is finally not usable, and I was unable to find any more workarounds. The runtime always crashes on InstallR[]. Because of the above-mentioned webpage, two people have already contacted me asking for new workarounds, but I couldn't help them. So now I'm asking here.

Is there any way to use RLink with R 3.5 on macOS?


Steps to reproduce the problem:

  • Install R 3.5, the latest version as of this writing.
  • Patch RLink with install_name_tool, as described at the end of this page
  • Start up RLink using

    << RLink`
    InstallR["RHomeLocation" -> "/Library/Frameworks/R.framework/Resources", "RVersion" -> 3]
    

Now the runtime crashes.

enter image description here

$\endgroup$
6
  • $\begingroup$ Have you asked Leonid? I find WRI support to be relatively unhelpful in general, but I remember Leonid corrected me when I proposed doing something with the RLink paclet and the way I read his comments it seemed as if he was involved. $\endgroup$
    – b3m2a1
    Commented May 12, 2018 at 9:14
  • 10
    $\begingroup$ @b3m2a1 Yes, I am the developer of RLink. I will file a bug and have a look into this. This looks pretty serious. $\endgroup$ Commented May 12, 2018 at 9:51
  • 7
    $\begingroup$ @Leonid I don't know if WRI would agree to it, but RLink might be a perfect candidate for open-sourcing. It only uses open-source components, and it is already decoupled from the M kernel. WRI could retain control by maintaining an official version. People could, and likely would, contribute improvements, which you would be able to accept/reject according to your judgement. It might also reduce the maintenance workload. $\endgroup$
    – Szabolcs
    Commented May 13, 2018 at 10:51
  • 4
    $\begingroup$ @Szabolcs I already have the internal ticket / task to open source it, so I guess now the main thing is to find the time to do this some time soon. $\endgroup$ Commented May 13, 2018 at 18:11
  • $\begingroup$ @Leonid Any progress yet on basic R 3+ connectivity and stability? Open Source is nice but first things first. I'm spending way too much time in RStudio. Thanks $\endgroup$
    – jcm
    Commented Jun 27, 2018 at 2:39

1 Answer 1

20
$\begingroup$

Possible workaround (one that I haven't tested too extensively)

Needs["RLink`"]

JLink`UninstallJava[];

InstallR["RVersion" -> 3, "RHomeLocation" -> "/Library/Frameworks/R.framework/Resources", 
  "NativeLibLocation" -> "/Library/Frameworks/R.framework/Resources/Library/rJava/JRI"];

REvaluate["R.version.string"]

(* {"R version 3.5.0 (2018-04-23)"} *)

This assumes that the JRI / rJava R package has been installed.

$\endgroup$
7
  • $\begingroup$ Thank you. This works, and also eliminates the need to patch libjri.jnilib. The crash on first-use is still there though. $\endgroup$
    – Szabolcs
    Commented May 13, 2018 at 10:30
  • 5
    $\begingroup$ Thanks, I updated the path and also worked around the JRE crash. $\endgroup$
    – ilian
    Commented May 13, 2018 at 13:31
  • 1
    $\begingroup$ Thanks, your findings will make my life simpler when looking into this issue. $\endgroup$ Commented May 13, 2018 at 18:09
  • 5
    $\begingroup$ I too regard this as an important issue. RLink is a great capability but the current installation problems create too high a barrier. I would urge Wolfram Research to spend some time and resources addressing the problems identified by the OP. $\endgroup$ Commented May 15, 2018 at 19:20
  • 1
    $\begingroup$ I mean how can anyone expect to rely on any feature of Mathematica if this is what happens to some features? $\endgroup$
    – Szabolcs
    Commented Jan 19, 2020 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.