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

  • 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. – b3m2a1 May 12 at 9:14
  • 10
    @b3m2a1 Yes, I am the developer of RLink. I will file a bug and have a look into this. This looks pretty serious. – Leonid Shifrin May 12 at 9:51
  • 7
    @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. – Szabolcs May 13 at 10:51
  • 4
    @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. – Leonid Shifrin May 13 at 18:11
  • @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 – jcm Jun 27 at 2:39
up vote 19 down vote accepted

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.

  • Thank you. This works, and also eliminates the need to patch libjri.jnilib. The crash on first-use is still there though. – Szabolcs May 13 at 10:30
  • The Versions/3.5/ bit may be removed from the path. – Szabolcs May 13 at 10:30
  • 5
    Thanks, I updated the path and also worked around the JRE crash. – ilian May 13 at 13:31
  • 1
    Thanks, your findings will make my life simpler when looking into this issue. – Leonid Shifrin May 13 at 18:09
  • 5
    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. – Seth Chandler May 15 at 19:20

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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