Wednesday, March 9, 2022

How to use Rstudio with multiple versions of R

Installing R and maintaining its the different versions are too much complicated. Almost everytime you install, Rstudio will downgrade your R versions and causes more problems than solutions.

And this is a simple solution for you:

#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" >> ~/.profileconda init bash

#2. Install Mamba

conda install mamba -n base -c conda-forge -y
conda update conda -y
conda update --all
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

#4. Install gdebi

To install GDebi on your Ubuntu machine, run the following command:

sudo apt-get install gdebi

#5. Install Rstudio

For Ubuntu, download the Rstudio *.deb package from the official Rstudio website. Download respectively for other Operating Systems.

Use gdebi to install the deb package, The gdebi command will ensure that all additional prerequisites are also downloaded to fulfil the RStudio requirements:

sudo gdebi rstudio-1.2.5019-amd64.deb

#6 Running Rstudio

Use your desktop menu to start the RStudio application or you can start the application by executing the below command : rstudio.

But that’s not why we did all this. We want different versions of R in Rstudio. For that run the following command in a terminal:

conda activate R

This will activate the installed conda R, now enter the command:

rstudio
This will make rstudio use the conda installed R.

0 comments:

Post a Comment