asdf-community / asdf-r

R plugin for the asdf version manager
https://github.com/asdf-vm/asdf
GNU General Public License v2.0
30 stars 6 forks source link

Integrating with RStudio for macOS #7

Open Nathaniel-Haines opened 3 years ago

Nathaniel-Haines commented 3 years ago

I am able to get asdf and RStudio working together very well on my Linux machine, but am having trouble with my macbook. On Linux, after setting an R version with asdf local R <version>, simply running rstudio in the project directory will open a new RStudio instance with the R version specified in .tool-versions.

However, on macOS, RStudio is opened using the open command like so: open -a rstudio. Doing so ignores the .tool-versions file, and instead opens an RStudio instance with the system R version as the back-end. I have tried specifying the RSTUDIO_WHICH_R environmental variable like so:

open -a rstudio --env RSTUDIO_WHICH_R=$HOME/.asdf/shims/R

But then I get the following error: Unable to find R_HOME_DIR in $HOME/.asdf/shims/R

I tried to set the R_HOME_DIR environmental variable to the respective asdf installation:

open -a rstudio --env RSTUDIO_WHICH_R=$HOME/.asdf/shims/R --env R_HOME_DIR=$HOME/.asdf/installs/R/<version>/lib/R

But this returns the same error as above. I am not quite sure why it works without any problems on Linux, but then gives me issues on macOS. I assume it has something to do with differences between the open command used on mac versus simply calling rstudio on Linux.

Curious if anyone has run into this issue/has come across a solution?

shepherdjerred commented 2 years ago

I was able to run RStudio with this command:

open -a studio --env RSTUDIO_WHICH_R=$HOME/.asdf/installs/R/4.2.1/bin/R

RStudio opens, but is then unable to find a .dylib.