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

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


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.)


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


Launch RStudio from Activated Conda Environment

At least for Mac OS X, I find that it is sufficient to activate the environment in a shell session, then launch RStudio.

$ conda activate my_r_env$ /Applications/RStudio.app/Contents/MacOS/RStudio

Once in R, one can verify that values of R.home() and .libPaths() point to the environment-specific locations.

The advantage here is that you aren't fixed to whatever was last set in the environment variables, e.g., via .bash_profile. Instead, one can have many R-based environments and switch between them (or run multiple ones simultaneously) without tampering with global settings.

Suggested Alias for Convenience

Perhaps the only global setting I might recommend is to add an alias for rstudio to your .bash_profile so you don't have to type the full path every time, like

alias rstudio='/Applications/RStudio.app/Contents/MacOS/RStudio &'

which enables one to then do

$ conda activate my_r_env$ rstudio$

where the & enables one to continue using the shell, or close it, without affecting the RStudio instance.