12
$\begingroup$

As of version 12.1, R is an officially supported external language, however, I can't seem to install any packages. I tried using my RStudio:

R = StartExternalSession[<|"System"->"R", 
      "Executable"->"/Applications/RStudio.app/Contents/MacOS/rsession"|>]
ExternalEvaluate[R, "install.packages('rjson')"]

enter image description here

Details:

  • Running MMA v12.1 on MacOS 10.15.3
  • I've first tried installing libs with the bundled R executable but no luck: Mathematica.app/Contents/SystemFiles/Links/RLink/Java/REngine.jar
$\endgroup$
6
  • 1
    $\begingroup$ ExternalEvaluate for R is based on RLink, so "Executable" parameter is ignored. Right now there is no way documented way for ExternalEvaluate to pick a user-defined version of R. Further, the currently bundled version of R is almost 8 years old (2.14) and lacks the ability to install packages. I am working on improving this situation as we speak, since finally I've got some chunk of time to spend on RLink. We will start bundling R 3.6.2 / 3.6.3 soon (couple of weeks from now). Package installation for bundled R is a harder problem (except on Windows), but I will see what I can do there. $\endgroup$ Mar 19, 2020 at 8:55
  • $\begingroup$ In 12.2 I am sure ExternalEvaluate will have an option to pick your own R installation. It is not clear if we can manage to get that into 12.1.1 release (which will be mostly a bug-fix release), but we'll see. I will post an answer here as soon as there will be enough progress on this. $\endgroup$ Mar 19, 2020 at 8:57
  • 1
    $\begingroup$ @LeonidShifrin when is the target release date for 12.1.1? And since now you guys have a paclet system in 12.1, can't you remotely update the existing installation of 12.1 rather than bundling fixes as a new release? Also please excuse my ignorance of the paclet system as I don't know whether it is capable of remotely updating parts of an existing installation, like PacletInstall["RLink"] and PacletInstall["ExternalEvaluate"]. $\endgroup$
    – user13892
    Mar 19, 2020 at 17:20
  • $\begingroup$ @user13892 For 12.1.1. I don't yet know the exact time frame, but it should be soon enough (I'd guess 4 - 6 weeks from now). RLink and bundled R I plan to paclet-update much sooner (hopefully, couple of weeks), and then indeed it should be just picked up. For ExternalEvaluate, I can't tell, since I am not a developer for it, but as I said, we will try to squeeze it in 12.1.1 (not sure if we could do that sooner for it). If I manage to solve the issue of package installation for bundled R, then that might be good enough for now, but that's a big if. I will post news here once I have it. $\endgroup$ Mar 19, 2020 at 17:48
  • $\begingroup$ @LeonidShifrin The bundled R is 8 years old!?! I can’t believe this, I was so excited to use external evaluation features with R, but now I can’t... :( Please please update this to at least version 3.4 if you can soon, would be much appreciated! $\endgroup$
    – user5601
    Mar 19, 2020 at 18:54

1 Answer 1

9
$\begingroup$

I was able to follow Leonid Shifrin's directions here for Mathematica 12.2 and R 4.0 running on Mac OS X 10.15.7. (I verified that R packages installed by me are accessible through RLink.) See the attached screenshot.

Needs["RLink`"]

InstallR[
  "RHomeLocation" -> 
   "/Library/Frameworks/R.framework/Versions/4.0/Resources",
  "RVersion" -> "4.0", 
  "NativeLibLocation" -> 
   "/Users/<yourhome>/Library/R/4.0/library/rJava/jri"]

ExternalEvaluate["R", "R.Version()"]

(* RObject[{{"x86_64-apple-darwin17.0"}, {"x86_64"}, \
{"darwin17.0"}, {"x86_64, darwin17.0"}, {""}, {"4"}, {"0.3"}, \
{"2020"}, {"10"}, {"10"}, {"79318"}, {"R"}, {"R version 4.0.3 \
(2020-10-10)"}, {"Bunny-Wunnies Freak Out"}}, 
 RAttributes[
  "names" :> {"platform", "arch", "os", "system", "status", "major", 
    "minor", "year", "month", "day", "svn rev", "language", 
    "version.string", "nickname"}]] *)

enter image description here

$\endgroup$

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.