Tuesday, June 28, 2022
HomeBioLit DailyInstall R in Conda

Install R in Conda

Installing R in Conda for version control

The more i used conda, i learned that installing R and maintaining the different versions are too much complicated. Given the fact that Rstudio will downgrade your R versions causes more problems than solutions.
With time as my friend, i learned the hard way that conda-forge is more reliable than installing from private repositories as it is tested and reviewed thoroughly by the Conda team.
Mamba is an almost complete rewrite of conda in C++, allows for parallel downloading of data, and has faster (and better) dependency resolving. For working with larger environments I’ve noticed tasks that would take tens of minutes only takes minutes now (if not less).
So here are new steps to install R.

1. Install Conda

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh \
&& chmod +x miniconda.sh && bash miniconda.sh -b -p miniconda

base_dir=$(echo $PWD)

export PATH=$base_dir/miniconda/bin:$PATH
source ~/.bashrc
echo -e "$base_dir/miniconda/etc/profile.d/conda.sh" >> ~/.profile
conda init bash

2. Install Mamba

conda install mamba -n base -c conda-forge -y
conda update conda -y
conda update --all

I usually set the conda-forge and bioconda channels to allow for downloading up-to-date biology software.
conda config --add channels defaults
conda config --add channels bioconda
conda config --add channels conda-forge

3. Install R

mamba create -n R -c conda-forge r-base -y
conda activate R
mamba install -c conda-forge r-essentials

Note: You can not update R-packages installed through r-essentials especially rcurl. So it is still not a very good way of installing R. Packages such as ComplexHeatMap packages and Cairo can not be installed.

4. Using rstudio

If you want to use studio, just activate your R environment in conda and whichever r-base version is available in that environment, studio will pick it up. So same rstudio can run on multiple R versions by switching between different R environments in conda.

Working with mamba

If you ever want to update the mamba software you can now update it similar to how conda is updated.
mamba update -n base mamba
If you want to search for an available package, the command is slightly different in mamba.
mamba repoquery search samtools
You also have the ability to check which packages the one you are searching for depends on.
mamba repoquery depends -a samtools

Ambu Vijayan
Ambu Vijayanhttps://www.biolit.in
Biotechnologist | Bioinformatician | Bio Statistician | R Programmer Founder of BioLit, AgriLit and BioScholar


Please enter your comment!
Please enter your name here

- Advertisment -spot_img

Most Popular

Recent Comments