Normally I create conda environments like...
conda env create -f environment.yml
conda activate env_name
Normally I work in Python, where a typical environment.yml
simple file might looks like this...
name: env_name
dependencies:
- python=3.7
- pip=19.3
- pandas=0.24.2
- pip:
- scipy==1.2.1
What should the environment.yml
file look like to install R packages? The packages are on CRAN
install r and r-essentials: conda install -c r r r-essentials. activate your new conda environment: conda activate clermonTyping. Open up R in the terminal: R. install whatever packages you need directly in R (in my case it was tidyverse and knitr): install.
yml file. Note that by convention Conda environment files are called environment. yml . As such if you use the conda env create sub-command without passing the --file option, then conda will expect to find a file called environment.
A general rule of thumb is that most R packages have corresponding packages in Anaconda Cloud with the prefix r-
added. While the defaults channel covers commonly-used packages, the conda-forge channel has the most thorough coverage of CRAN and has helpful scripts for adding new ones. I would generally recommend prioritizing conda-forge when creating R environments.
For bioinformaticians, all Bioconductor packages are available through the bioconda channel, with a bioconductor-
prefix and lowercase. For example, SingleCellExperiment
is packaged as bioconductor-singlecellexperiment
.
A good place to start is simply searching Anaconda Cloud (example search).
Let's assume you want the tidyverse
umbrella package and wish to use R v4.1. A YAML for this would be
name: my_r_env
channels:
- conda-forge
dependencies:
- r-base=4.1
- r-tidyverse
Avoid using install.packages()
from within any R sessions - it is prone to dynamic linking issues due to the R instance's unawareness of compiling inside the environment. This is not an issue for pure R packages, but in that case it should be simple to add the package to conda-forge (takes about 15 mins of work and a ~12-24hr turnaround, IME).
Avoid the RStudio packages from Conda - it is an abandoned project and the old versions are incompatible with newer R versions. This may change once RStudio switches from Qt to Electron. Still, there are better ways to load an environment into RStudio, without having to install the full IDE inside the environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With