Skip to content

Installing R and adding packages without Root permissions.

Vijender Singh edited this page Aug 11, 2021 · 26 revisions

R programming language is preferred by many for data analytics and statistical computing. There are packages available to do various kinds of bioinformatics and statistical analysis, which avoid a user to develop scripts and analysis methods from scratch. These packages are available from 3 different sources

  1. CRAN webpage
  2. Bioconductor
  3. Github

Many a time the installation of some packages requires root or administrator privileges and that may not be available on cluster systems. We put an outline below to explain how to install R and the packages without the root/administrator permissions using miniconda. The tutorial is explained in four steps

  1. Installation of miniconda and creating an environment
  2. Installation of R
  3. R-package installation
  4. Running R

Lets get started

Step1: Installation of miniconda and creating an environment

Start interactive session srun –-pty -p general -q general –mem=5G bash

  1. Download miniconda for appropriate python version from https://docs.conda.io/en/latest/miniconda.html . Select the appropriate version and right-click and select “Copy Link Address”. miniconda download

Use the command to down load the link wget <paste the copied link here>

  1. Execute the downloaded script as sh Miniconda3-latest-Linux-x86_64.sh

Agree to license, location and for running conda init

  1. Execute command conda at terminal and if it display conda help file you have installed miniconda properly.

  2. Now we would like to create an environment which will have appropriate version of python and required python packages in it. Let say we want to create an environment named python3 (any name can be given) with python-3.8. Execute the command

conda create -n python3 python=3.8

  1. Once environment is created you can install packages you require e.g ipython. Google “ipython conda installation” and among different option suggested select one which is from anaconda website as shown below package search

  2. Once on anaconda website find the channel (-c) and installation instructions as shown below channel selection

  3. Install the package with command and specifying the environment name.

conda install -n python3 -c anaconda ipython

This will install the package from appropriate channel in appropriate environment. In future if you would like to add another package for the same environment, simply find the channel and installation instruction from anaconda website (as we did for ipython) and run the installation command as

conda install -n python3 -c <channel> <PackageName>

This is the only line you have to execute in an interactive session for a package to be added to the environment.

Installation of R

In order to install R, we will be first creating an environment for R so that it is isolated from other environments but this is optional.

  1. Create an environment for R and lets name the environment as R411 (Installing R version 4.1.1).

conda create -n R411

and now switch to the new environment with code

conda activate R411

  1. In this environment we will be installing 4.1.1 version of R

conda install -c conda-forge r=4.1.1

Similarly, older version of R can also be installed by specifying the version in the above command.

  1. Now lets check if installation is successful

conda deactivate

conda activate R411. Load the environment

which R. # This should display the path to R as some/path/R411/bin/R

or

R. # Here the loaded R should be R version 4.1.1

Run conda deactivate to close the environment.

Now any time you need to use R load the environment