Skip to content

Instantly share code, notes, and snippets.

@npicciani
Last active March 16, 2022 20:59
Show Gist options
  • Save npicciani/e40d836fb6fd7b15584b133181fd7be0 to your computer and use it in GitHub Desktop.
Save npicciani/e40d836fb6fd7b15584b133181fd7be0 to your computer and use it in GitHub Desktop.
How to use a Conda environment in RStudio

Loading RStudio from a Conda environment

I wanted to load a conda environment for working in RStudio and keep all my packages for a particular project separated from my base environment.

So I peeked on instructions here:

https://alexanderlabwhoi.github.io/post/anaconda-r-sarah/

I created a conda environment with the latest r-version and essential packages by typing:

$ conda create --name dynverse -c conda-forge r-essentials r-base=4.1.2

At this step, I had trouble also installing RStudio within the environment. For some reason it was spitting out an error about python version 3.1 not available.

But if you already have RStudio installed as an application in your Mac, you don't have to re-install it. You can just call the app once the environment is loaded.

As suggested in https://stackoverflow.com/questions/38534383/how-to-set-up-conda-installed-r-for-use-with-rstudio

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

And also as suggested, to avoid typing the whole path everytime you want to launch RStudio, you can make an alias for it in your bash_profile - or in the file ~/.zshrc in case your default shell is zsh rather than bash; check with echo $SHELL

$ nano ~/.bash_profile

Add the line:

alias rstudio='/Applications/RStudio.app/Contents/MacOS/RStudio &'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment