R

Overview

R is a free software environment for statistical computing and graphics.

incline2000

From 1st Aug 2024, the only nodes in the iCSF are the 2TB nodes, which received an operating system upgrade. Following this upgrade, some of the older versions of R (and Rstudio) may not run.

We strongly encourage all users to move to the newer versions of R (see below), which have been built for the new operating system on the iCSF.

Using R on the iCSF AND ALSO CSF3

If you intend to use R on the iCSF AND ALSO the CSF3, then you should read this section.

If you only use the iCSF, you can skip this section.

The operating system on the iCSF nodes is now newer than that on CSF3. So from now on, any packages you install in to a “personal” library using install.packages("thing"), while you are logged in to the iCSF, will very likely NOT run on CSF3, due to older system libraries on that system.

So to prevent a package installed on the iCSF from polluting your personal library on CSF3, please load the following modulefile:

# Additional modulefile for people using R on the iCSF who also use R on
# CSF3. This modulefile is ONLY available on the iCSF nodes!!!
# Load this AFTER loading an 'apps/gcc/R/x.y.x' modulefile on the iCSF.

module load apps/gcc/R/incline2000-fix

This will force any subsequent package installs performed on the iCSF into a separate ~/R/el9/ directory tree, away from the default tree ~/R/ used on the CSF3. It will prevent you breaking your CSF3 package installs.

But it does mean that if you install a package on the iCSF, it WON’T be visible to R on the CSF3. You’ll need to login to CSF3 and install it again, for use on CSF3.

In summary:

  • Package installs performed on the iCSF may NOT run on CSF3
  • Package installs performed on CSF3 will probably run OK on the iCSF
  • The apps/gcc/R/incline2000-fix modulefile will keep your iCSF package installs away from your CSF3 install area. You will still be able to see your CSF3 installs when on the iCSF (they might still work.) But you won’t see your iCSF installs when on CSF3 (they probably won’t work anyway.)

If you need further information about R packages installs on the iCSF and CSF3, please contact its-ri-team@manchester.ac.uk.

Versions available

Please see the Setup procedure section below for the modulefile commands that will make a particular version available to your login session.

The following versions are installed on the iCSF:

These versions are for use on the iCSF nodes, following the operating system upgrade. You are strongly encouraged to begin using version 4.4.0 or newer.

  • R 4.4.2 – includes GCC 14.2.0
  • R 4.4.1 – including a non-optimised version to resolve issues with certain packages/fuctionality (4.4.1-nonopt) – see below.
  • R 4.3.3 – please upgrade to using 4.4.0 or newer
  • R 4.1.3 – please upgrade to using 4.4.0 or newer
  • R 4.1.2 – please upgrade to using 4.4.0 or newer
  • R 4.0.2 – please upgrade to using 4.4.0 or newer

Versions below here here may not run correctly on the upgraded iCSF nodes – please use a newer version (see above.) Note that the old incline256 nodes are no longer available (1st Aug 2024.)

  • R 4.3.2
  • R 4.3.1
  • R 4.1.2-gcc830 – includes BioConductor 3.13 and ukbtools 0.11.3, only on incline256 boxes
  • R 4.0.2-gcc830
  • R 3.6.1-gcc830 – includes BioConductor 3.9.0 & ukbtools 0.11.3 # only on incline256 boxes. Uses newer C++ compiler which will allow most user-packages to install correctly (those that need C++11 and C++14)
  • R 3.6.1 # all incline node types but some user-packages may not install correctly (those that need C++11 and C++14)
  • R 3.6.0 – includes BioConductor 3.7 & ukbtools 0.11.2 # only on incline256 boxes
  • R 3.5.2 – includes BioConductor 3.5 & ukbtools 0.9.0 # only on incline256 boxes
  • R 3.4.2 – includes BioConductor 3.5 & ukbtools 0.9.0
  • R 3.4.1 – includes BioConductor 3.5 & ukbtools 0.9.0
  • R 3.3.3 – includes BioConductor 3.3 (Rcmdr is not installed).
  • R 3.3.0 – includes BioConductor 3.3 (Rcmdr is not installed).
  • R 3.2.3 – does not include Bioconductor or Rcmdr
  • R 3.2.3-ambs – as per 3.2.3 but with a number of additional packages – see updates at the bottom of this page for full details.
  • R 3.2.0 – includes BioConductor 3.1 (please note Rcmdr does not work in this version)
  • R 3.1.0 – includes BioConductor 2.14
  • R 3.0.2
  • R 2.15.3 – includes BioConductor 2.11
  • Microsoft R Open 3.2.4 – does not include BioConductor. It does include MKL libraries for parallel matrix calculations

Bioconductor is included in some of the central iCSF installations of R. Not all associated packages may be available, but you can install them to your own home directory using the Adding BioConductor Packages instructions below, in conjunction with information from the bioconductor website.

Alternatively, we may be able to add them to the central install – contact its-ri-team@manchester.ac.uk .

Restrictions on use

There are no restrictions on access to R as it is a free piece of software released under a GNU license. All users should familiarise themselves with the licensing information available via the R website.

Setup procedure

To access the executables please load an appropriate modulefile.

Note, if you wish to use Rstudio, load the R modulefile first, then please see the Rstudio page for a list of available modulefiles.

# We recommend all users upgrade to using the latest version of R
module load apps/gcc/R/4.4.1

# If you experience crashing in 4.4.1 (either at the command-line or in Rstudio),
# please try this 'nonopt' version which has been compiled without optimization (-O0)
# to resolve some crashes we've seen in various libraries and functions.
module load apps/gcc/R/4.4.1-nonopt

# Please upgrade to 4.4.1 if using these versions
module load apps/gcc/R/4.3.3
module load apps/gcc/R/4.1.3
module load apps/gcc/R/4.1.2
module load apps/gcc/R/4.0.2

# Additional modulefile to consider loading after loading one of the above:
# If using CSF3 as well as iCSF, and you have problems with R libraries not running on CSF3,
# this modulefile will keep your iCSF library installs away from your CSF3 library installs.
# Problems can occur when the CSF tries to use R libraries that were installed on the iCSF.
# (If you do use this, load it before installing any R libraries, and every time you use R.)
module load apps/gcc/R/incline2000-fix

The following versions were installed for the now-retired incline256 nodes. They may not run on the incline 2TB nodes (please try them.)

If you have problems running any of the following versions, please consider using one of the above newer versions. You’ll need to reinstall any R libraries you’ve installed.

# If these versions do not run on the upgraded iCSF nodes, we are unlikely to reinstall them.
# Please move to a newer version of R (see above.) 
module load apps/gcc/R/4.3.1
module load apps/gcc/R/4.1.3-gcc830 
module load apps/gcc/R/4.1.2-gcc830
module load apps/gcc/R/3.6.1-gcc830
module load apps/gcc/R/3.6.1
module load apps/gcc/R/3.6.0
module load apps/gcc/R/3.5.2
module load apps/gcc/R/3.4.2
module load apps/gcc/R/3.4.1
module load apps/gcc/R/3.3.3
module load apps/gcc/R/3.3.0
module load apps/gcc/R/3.2.3
module load apps/gcc/R/3.2.3-ambs
module load apps/gcc/R/3.2.0
module load apps/gcc/R/3.1.0         # Fixes a font problem in v3.0.2
module load apps/gcc/R/3.0.2
module load apps/gcc/R/2.15.3        # Rcmdr not available in this version

Microsoft R Open with MKL (this is an old version, we recommend the open source versions above.)

module load apps/gcc/MRO/3.2.4

Running the application

Having loaded the appropriate modulefile, simply run:

R

# To ensure no previously save large objects are loaded, which might cause memory issues
# from previous runs of R if you were processing a large dataset, use:
R --no-restore-data

# Or use --vanilla, which applies the following flags
# --no-save, --no-restore, --no-site-file, --no-init-file and --no-environ
R --vanilla

PLEASE NOTE: If more than one R module file is loaded it will default to the version which has been loaded most recently.

You will now be at the R prompt.

To exit R, type:

q()

To start the GUI, enter library(Rcmdr) at the R command line:

library(Rcmdr)

Loading required package: tcltk
Loading Tcl/Tk interface ... done

If you are using Microsoft Open R then please note that you do not have exclusive access to iCSF compute nodes so it is highly recommended that you set:

export OMP_NUM_THREADS=4

to avoid the software trying to use the whole node and interfering with other people’s work.

Adding packages

Packages that provide extra functionality can be added to R by allowing R to save them in to your iCSF home directory. Packages can be downloaded automatically by R (if it can find the package associated with the library you are requesting) or you can supply a source package for R to unpack and install. The download method is preferred. Follow the instructions below:

Automatically Download from CRAN

To add packages that will be downloaded by R from the CRAN (cran.r-project.org):

  1. Check whether you have a ~/.Renviron file – it may contain some old, out-of-date proxy settings which need to be removed.
    # Note: you may have old proxy settings in an ~/.Renviron file. You'll need to remove these:
    cat ~/.Renviron
      #
      # If you see the following, you do not need to do anything!
      cat: .Renviron: No such file or directory
    
      # If you see some lines containing
      http_proxy=http://proxy.man.ac.uk:3128
      https_proxy=https://proxy.man.ac.uk:3128
        #
        # DELETE these lines or place a # at the start of each line.
    
      # If your ~/.Renviron file contains only the above proxy lines
      # you can delete the file
      rm ~/.Renviron
    
  2. Start R in the usual way (choose the version of R you require):
    module load apps/gcc/R/3.2.0
    R
    
  3. Ask R to install the required package and answer y when asked if you wish to create a personal library:
    > install.packages("thing")
    Warning in install.packages("thing") :
    'lib = "/opt/gridware/apps/gcc/R/3.2.0/lib64/R/library"' is not writable
    Would you like to create a personal library
    ~/R/x86_64-unknown-linux-gnu-library/3.0
    to install packages into?  (y/n) y
    
  4. Select a UK mirror when prompted.
    • Note, you may have to select a mirror name that does not have [https] next to it.
  5. Then to use the package in R, load the library in R:
    library(thing)
    

nloptr dependency

This problem does NOT occur in recent versions of R (e.g., 4.4.1.) If you do have a problem with R libraries not installing correctly, please read this section.

Some packages fail to install because they depend on the nloptr R package. Trying to install that specific package often fails due to a dependency on the nlopt library, which R fails to compile. So we have provided this as a separate modulefile. For example:

# This will fail due to a failure to compile nloptr
module load apps/gcc/R/4.3.1
R
install.packages("nloptr")           # Other R packages that depend on this one will also fail
q()

# The solution is to load an extra modulefile:
module load libs/gcc/nlopt/2.7.1
R
install.packages("nloptr")

Rcpp dependency

This problem does NOT occur in recent versions of R (e.g., 4.4.1.) If you do have a problem with R libraries not installing correctly, please read this section.

We’ve seen some R packages fail to install due to a failure in R to compile the Rcpp dependency.

The solution was to do the Rcpp package first, then do the package you want to install. For example:

# Install the lme4 packages, which requires nloptr and Rcpp:
module load libs/gcc/nlopt/2.7.1
R
install.packages("nloptr")
install.packages("Rcpp")
install.packages("lme4")

# Test
library(lme4)
q()

In the above instructions replace the module load command with the one appropriate to the R version you wish to use.

Library from Source

If you’ve downloaded an R library source file you can add it to your local workspace using the following commands (which assume the source package is in your home directory on the iCSF):

  1. Start R with extra command-line args (choose the version of R you require):
    module load apps/gcc/R/3.2.0
    R CMD INSTALL thing.x.y.z.tar.gz
    
    * installing to library ‘/mnt/iusers01/support/mabcxyz1/R/x86_64-unknown-linux-gnu-library/3.2’
    * installing *source* package ‘thing’ ...
    ** package ‘thing’ successfully unpacked and MD5 sums checked
    ** R
    ** data
    ** demo
    ** preparing package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** testing if installed package can be loaded
    * DONE (thing)
    

    Alternatively,

    module load apps/gcc/R/4.3.1
    R
    packageurl <- "https://cran.ma.imperial.ac.uk/src/contrib/Archive/nloptr/nloptr_1.2.1.tar.gz";  install.packages(packageurl, repos=NULL, type="source");
    install.packages('lme4')
    
  2. Now run R and test that the library can be loaded:
    R
    > library(thing)
    

The compiled library files will be save in a directory named R in your home directory. It contains subdirectories for each version of R so if you want to use the library in different versions of R you will have to repeat the above commands for each version.

Adding BioConductor Packages – R 3.6.0 and newer

Note: This is NOT the method used for older versions of R (3.5 and older). See below for that.

The ‘manager’ for bioconductor has changed in version 3.6.0. Details are given here on how to install BioConductor packages in R 3.6.0 (and up).

# Check the BiocManager version
BiocManager::version()

# See what is installed
BiocManager::available()

# Install a package to your home directory
BiocManager::install(c("esATAC"))
                           #
                           # Use the name of the package you want to install.
                           #
                           # You will be prompted to install to a local directory
                           # (i.e., your home directory) as shown below.

### Select from a UK Mirror when prompted (e.g., the UK Bristol mirror)

Bioconductor version 3.9 (BiocManager 1.30.4), R 3.6.0 (2019-04-26)
Installing package(s) 'esATAC'
Warning in install.packages(pkgs = doing, lib = lib, repos = repos, ...) :
  'lib = "/opt/gridware2/el7/apps/gcc/R/3.6.0/lib64/R/library"' is not writable
Would you like to use a personal library instead? (yes/No/cancel) y   # Answer 'y'
Would you like to create a personal library
‘~/R/x86_64-pc-linux-gnu-library/3.6’
to install packages into? (yes/No/cancel) y                           # Answer 'y'

See below for how to then use (load) an installed BioConductor package.

Adding BioConductor Packages – R 3.5 and earlier

Note: This is NOT the method used for newer versions of R (3.6 and newer). See above for that.

BioConductor packages or packages that rely on bioconductor packages can be installed in to your local R library (in your home directory) as follows (this example assumes use of R 3.2.0):

  1. Check whether you have a ~/.Renviron file – it may contain some old, out-of-date proxy settings which need to be removed.
    # Note: you may have old proxy settings in an ~/.Renviron file. You'll need to remove these:
    cat ~/.Renviron
      #
      # If you see the following, you do not need to do anything!
      cat: .Renviron: No such file or directory
    
      # If you see some lines containing
      http_proxy=http://proxy.man.ac.uk:3128
      https_proxy=https://proxy.man.ac.uk:3128
        #
        # DELETE these lines or place a # at the start of each line.
    
      # If your ~/.Renviron file contains only the above proxy lines
      # you can delete the file
      rm ~/.Renviron
    
  2. Now load a version of R that has bioconductor installed, e.g.
    module load apps/gcc/R/3.2.0
    
  3. Start R in the usual way and tell it you need to use BiocInstaller
    > require('BiocInstaller')
    Loading required package: BiocInstaller
    Bioconductor version 3.1 (BiocInstaller 1.18.1), ?biocLite for help
    
  4. Next install the required packages
    > biocLite(c("WGCNA"))
    

    and when it asks if you want to use a personal library answer y

    Would you like to use a personal library instead?  (y/n) y
    trying URL 'http://bioconductor.org/packages/3.1/bioc/src/contrib/BiocInstaller_1.18.5.tar.gz'
    Content type 'application/x-gzip' length 14977 bytes (14 KB)
    ==================================================
    downloaded 14 KB
    
    * installing *source* package ‘BiocInstaller’ ...
    ** R
    ** inst
    ** preparing package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** testing if installed package can be loaded
    Bioconductor version 3.1 (BiocInstaller 1.18.5), ?biocLite for help
    A newer version of Bioconductor is available for this version of R,
      ?BiocUpgrade for help
    * DONE (BiocInstaller)
    
    The downloaded source packages are in
    	‘/tmp/RtmpMwCszR/downloaded_packages’
    Bioconductor version 3.1 (BiocInstaller 1.18.5), ?biocLite for help
    A newer version of Bioconductor is available for this version of R,
      ?BiocUpgrade for help
    'BiocInstaller' updated to version 1.18.5
    BioC_mirror: http://bioconductor.org
    Using Bioconductor version 3.1 (BiocInstaller 1.18.5), R version 3.2.0.
    Installing package(s) ‘WGCNA’
    also installing the dependencies ‘impute’, ‘GO.db’
    
    ------- SNIP ------
    
  5. It should install any dependencies that are missing. At the end it may ask if you want to update some other/old packages – say n as most of them will be part of the central install which you do not have permission to change.
    ------- SNIP ------
    * DONE (WGCNA)
    
    The downloaded source packages are in
    	‘/tmp/RtmpMwCszR/downloaded_packages’
    Old packages: 'abind', 'annotate', 'base64', 'BiocInstaller', 'BiocParallel',
      'biomaRt', 'Biostrings', 'boot', 'car', 'class', 'cluster', 'codetools',
      'DBI', 'digest', 'e1071', 'edgeR', 'effects', 'evaluate', 'foreach',
      'foreign', 'formatR', 'futile.logger', 'GenomeInfoDb', 'GenomicAlignments',
      'GenomicFeatures', 'GenomicRanges', 'ggplot2', 'gridExtra', 'gtable',
      'highr', 'Hmisc', 'IRanges', 'iterators', 'KernSmooth', 'knitr', 'lambda.r',
      'lattice', 'latticeExtra', 'limma', 'lme4', 'lmtest', 'MASS', 'Matrix',
      'matrixStats', 'mclust', 'mgcv', 'mime', 'multcomp', 'munsell', 'mvtnorm',
      'nlme', 'nnet', 'nor1mix', 'plyr', 'quantreg', 'Rcmdr', 'RcmdrMisc', 'Rcpp',
      'RcppEigen', 'RCurl', 'registry', 'relimp', 'rgl', 'rJava', 'RODBC', 'rpart',
      'Rsamtools', 'rtracklayer', 'ruv', 'S4Vectors', 'sandwich', 'scales', 'sem',
      'snow', 'SparseM', 'spatial', 'statmod', 'stringi', 'survival', 'TH.data',
      'XLConnect', 'XLConnectJars', 'XML', 'xtable', 'zoo'
    Update all/some/none? [a/s/n]: n
    
  6. Test you can load the package
    library("WGCNA")
    

Using BioConductor Packages

BioConductor packages have to be loaded like any other package if you’ve previously installed them. For example, assuming you have installed a BioConductor package named bioThing, to use it in your code use:

# Load/use a BioConductor package named 'bioThing' previously installed
library(bioThing)

Listing Packages

To list the installed packages run:

installed.packages();

To list loaded packages run:

(.packages())

Hints and Tips (let us know yours)

Plotting Graphs and Graphics

To see the available graphics file formats support, run the capabilities() function in R. Note that newer versions of R (e.g., 3.6.0-gcc830) have more graphics formats supported – we recommend you use the latest version of R available on the iCSF:

ssh username@incline256.itservices.manchester.ac.uk
[mabcxyz1@incline26 ~]$ module load apps/gcc/R/3.6.1-gcc830
[mabcxyz1@incline26 ~]$ R
> capabilities()
       jpeg         png        tiff       tcltk         X11        aqua 
       TRUE        TRUE       TRUE        TRUE        TRUE       FALSE 

The following example generates a histogram and plots it to a .png file and a .jpg file. It has been tested on the incline256 nodes.

# R script to demonstrate plotting to image files on the iCSF

# Enable cairo device - MAC USER: THIS MIGHT FIX SOME FONT PROBLEMS.
options(bitmapType='cairo')

# Initialize some data to plot
x = rnorm(100)

# Save a png plot
png(file="hist.png")
hist(x)
rug(x,side=1)
dev.off()

# How about jpg
jpeg(file="hist.jpg")
hist(x)
rug(x,side=1)
dev.off()

# R 3.6.1 can also do tiff
tiff(file="hist.tif")
hist(x)
rug(x,side=1)
dev.off()

# Exit
q();

Now to view your images while on the iCSF, use the eye of gnome (eog) image viewer:

# List the image files created by the above example
ls hist.*
hist.jpg  hist.png  hist.tif

# Use the image viewer name 'eog' (Eye of Gnome)
eog hist.png

If you need other image file formats you can then convert your PNG file using the convert command-line tool, available on the login node or can be run in your jobscript (note that convert is a linux command-line program, not an R function):

# Using the hist.png example file from the above R script, convert it to another format:
convert hist.png hist.tif      # R 3.6.1 can write tif files directly (see above) but older versions can't

# How about a .pdf
convert hist.png hist.pdf

# View the PDF file
evince hist.pdf

Another example of plotting to file:

png(file = "myplot.png", bg = "transparent")
plot(1:10)
rect(1, 5, 3, 7, col = "white")
dev.off()

## will make myplot1.jpeg and myplot2.jpeg
jpeg(file = "myplot%d.jpeg")
example(rect)
dev.off()

Further info

For software documentation and FAQs please consult the R Project website.

See also the Bioconductor website.

Updates

August 2024 – Only the 2TB nodes remain and have been upgraded to an EL9 O/S. R 4.4.x versions installed. Older versions may not run.
August 2017 – v3.4.1 added
July 2016 – a version of rjava has been compiled for R version 3.3.0 and has all the java environment variables automatically set. It can be accessed using:module load apps/gcc/rjava/0.9.8-R3.3.0.
29.01.2016 – v3.2.3-ambs added including the packages: ggplot2, randomForest, dplyr, party, DataCombine, Imtest, Foreign, Hmisc, lattice, survival, Formula.
29.01.2016 – v3.2.3 added
11 May 2015 – v3.2.0 added
9-June-2014 – v3.1.0 added

Last modified on November 8, 2024 at 10:18 am by Abhijit Ghosh