Selecting among multiple R versions with RSTUDIO_WHICH_R on Mac

I am trying to run R (development) version 4.0 that I compiled from source on a mac as the engine in RStudio. According to the documentation Rstudio for Mac scans for the R executable in the following sequence:

  1. /usr/bin/R
  2. /usr/local/bin/R
  3. /opt/local/bin/R
  4. whatever version of R is located at /Library/Frameworks/R.framework/

and this can be overridden by setting the environment variable RSTUDIO_WHICH_R.

Well, I have a working install at location 2 (ie, can run it from Terminal no problem) and have also tried exporting RSTUDIO_WHICH_R=/usr/local/bin/R, then opening RStudio with open -an RStudio in a Terminal. I can verify in Rstudio that the environment variable was set with Sys.getenv and points to a file:

> file.exists(Sys.getenv('RSTUDIO_WHICH_R'))

[1] TRUE

But I can't for the life of me get RStudio to run anything but the version linked in /Library/Frameworks/R.framework/. So I suspect that this documentation is no longer accurate for MacOS. Has anyone actually observed the documentation to be accurate?

This is with Rstudio 1.2.5033, R 3.6.1 installed in Frameworks and r77542 installed under /usr/local/bin on a Mac. Running Mojave 10.14.6.


After reading the rstudio source and trying to understand how RSTUDIO_WHICH_R is used, I saw that there was some logging occurring. In ~/.rstudio-desktop/log/rdesktop.log I see the following:

18 Dec 2019 05:50:30 [rdesktop] ERROR Unable to find libR.dylib in expected locationswithin R Home directory /usr/local/lib/R-4.0.0-devel; LOGGED FROM: bool rstudio::core::r_util::(anonymous namespace)::getLibPathFromRHome(const rstudio::core::FilePath &, std::string *, std::string *) /Users/vagrant/workspace/IDE/macos-v1.2/src/cpp/core/r_util/REnvironmentPosix.cpp:140

So it seems I need to set --enable-R-shlib when I compile R...stay tuned.


Update 2

I recompiled with


and ran make install which put R in the usual Mac location of /Library/Frameworks/R.framework/ and got everything to work.

Before trying that (in hopes that I could manage the R versions without manually updating the symlinks in /Library/Frameworks, ie, make shell scripts that run RStudio against a specific version of R), I compiled with --enable-R-shlib. RStudio did indeed find the version at /usr/local/bin either with, or without setting RSTUDIO_WHICH_R, per documentation. However as RStudio initialized, I got an error about library/utils/libs/ not being able to resolve libR.dylib (which was in the usual spot for a unix architecture), so I suspect there's a #IFDEF __APPLE__ that is causing RStudio to set library paths in a manner that is consistent only with the Frameworks-style installation.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.