Page tree
Skip to end of metadata
Go to start of metadata

R and RStudio are available within the Research Environment. You can use the latest version of R, as well as specifying previous versions if you like. It is also possible to install R packages from both CRAN and BioConductor using the internal mirror. 

Follow the steps below to configure your environment to install R packages. 

Selecting a version of R to use

The default install of R on the Desktop is version 3.4.3. The default version of R in RStudio is 3.4.3.

To use a specific version of R in RStudio, open the terminal app on the Desktop and enter the following commands:

module avail R/
module load R/3.4.0 #select your version here

This will firstly scan for all available versions of R and then load RStudio using R 3.4.0. 

This is important, as there are different libraries available for the different versions of R. For a full list of pre-installed libraries per R version, see libraries available in R.

Installing R packages from CRAN

You can install R packages yourself within the Research Environment from CRAN as we have an internal mirror ( 

(warning) Note that you can only install R packages from the Desktop environment. You cannot install R packages directly on the HPC (warning)

Installation from the Desktop environment

The default R installation within the Research Environment Desktop contains just the base packages. If you want to to install packages yourself you have to do the following:

  1. Open the terminal application from the Desktop.
  2. Type nano ~/.Rprofile into the terminal window.
  3. Type in (or copy-and-paste) the following lines to the file open in the terminal:

    myrepo = getOption("repos")
    myrepo["CRAN"] = ""
    options(repos = myrepo)

  4. Press 'Ctrl+x' to exit and then 'y' to save, and then <enter> to confirm.
  5. Open RStudio from the Desktop or type R in a terminal window to start R.
  6. Type the command getOption("repos") - which should show that has been configured as the CRAN repository for R packages.
  7. You can now install a package:
    1. Make a folder where you want to store your R packages for example: '~/re_gecip/yourDomain/R_packages'
    2. Install the package and specify the installation path with lib: install.packages("<package>", lib="~/re_gecip/yourDomain/R_packages")
    3. Load libraries: library(<package>, lib="~/re_gecip/yourDomain/R_packages")

All R packages that are located on GitHub require Genomics England admins to install them. Please submit a service desk ticket if you require this.

Loading from the HPC environment

You can only install R packages form the Desktop environment. If you need to use these packages on the HPC environment then you'll need to install the packages to a folder on the Desktop that is writeable and mounted on the HPC. Please use your specific shared folder to do this. If you are in GeCIP, then your specific shared folder is called 're_gecip'. To load a pre-installed R package from the HPC environment you can use the following command: library(<package>, lib="/re_gecip/yourDomain/R_packages"). Notice the preceding '/' in the HPC environment compared to '~/' in the Desktop environment. 

Installing packages from BioConductor

You can also install BioConductor packages from within the Research Environment after a once-off configuration as shown below. Follow the same setup as CRAN packages by installing them to a shared folder on the HPC (such as 're_gecip'). 

  1. Open the terminal application from the Desktop.
  2. Type nano ~/.Renviron into the terminal window
  3. Type in (or copy-and-paste) the following lines to the file:



  4. Press 'Ctrl+x' to exit and then 'y' to save, and then <enter> to confirm.
  5. Open R (or RStudio) and install BioConductor packages as normal

Plotting in R on the HPC

When R is run on the HPC as a module, it will not be able to output plots. You might see errors such as: Unable to start device PNG, Unable to open connection to X11 display.

This can be solved by using an X Virtual Frame Buffer to run R in. The below is an example of how to do this:

module load R/3.5.1
xvfb-run -a R

If, however, you do not want to write xvfb-run R each time, then you can set up an alias in your .bashrc file that will do this for you. Add the following line to your .bashrc file:

alias R='xvfb-run -a R'

A quick example of saving an R plot to disk:


This will create a .png file called plot.png in the current working directory with your data plotted.

  • No labels