How to set up conda-installed R for use with RStudio?

Update: ADD THIS TO ~/.bash_profile !

export RSTUDIO_WHICH_R="/Users/jespinoz/anaconda/bin/R"
launchctl setenv RSTUDIO_WHICH_R $RSTUDIO_WHICH_R

Credits to @Z-Shiyi for the last line https://github.com/conda/conda/issues/3316#issuecomment-241246755


An addition to what @Ray Donnelly said above. Basically, it has to be executed from the correct environment (i.e. run it from the terminal).

You can either:

(A) Put this in your ~/.bash_profile export RSTUDIO_WHICH_R=/Users/[yourusername]/anaconda/bin/R (if youre using conda but you could put any R path)

(B) then type this in the terminal after it's been sourced (either restart terminal or do source .bash_profile): open -a RStudio That should work.

or you can do what I did:

(A) open up automator (sorry if you're not on a mac; this will only work on mac)

(B) use a Run Shell Script

(C) then delete cat that's already in there and put in: export RSTUDIO_WHICH_R=/Users/[yourusername]/anaconda/bin/R open -a RStudio

(D) Save it as something like run_rstudio.app then just run that and it should work: enter image description here


So long as which R shows up a working R interpreter (which it should do if you have installed the r package from conda and activated your environment) then launching rstudio from that same environment should pick it up just fine.

For a test, on ArchLinux, I built and installed: https://aur.archlinux.org/packages/rstudio-desktop-git/

.. then force removed the R interpreter (pacman -Rdd r), then installed r from conda (conda install -c r r) and it worked fine. I then closed my terminal and opened a new one (so that the correct conda environment was not activated and successfully launched RStudio with the following command: RSTUDIO_WHICH_R=/home/ray/r_3_3_1-x64-3.5/bin/R rstudio

I think the crux is to launch RStudio from the right environment? Your ~/.bash_profile and ~/.bashrc are only sourced when you run bash. For environment variables to be set so that the your desktop environment knows about them, on Linux, you should put them in ~/.profile or else in /etc/pam.d (you may need to logout or shutdown after making those changes) and on OS X, you should check out https://apple.stackexchange.com/q/57385


See https://anaconda.org/r/rstudio:

$ conda install -c r rstudio

Then from command line:

$ rstudio

(It is how I installed it and it works.)