R
Overview
R is a free software environment for statistical computing and graphics.
The following versions are installed on the iCSF:
- Microsoft R Open 3.2.4 – does not include BioConductor. It does include MKL libraries for parallel matrix calculations
Standard open source R
- 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
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.
Set up procedure
To access the executables please load the appropriate modulefile:
Microsoft R Open with MKL:
module load apps/gcc/MRO/3.2.4
Standard open source R:
module load apps/gcc/R/4.3.1 module load apps/gcc/R/4.1.2-gcc830 # incline256 boxes only (user-package installs should # work if C++11/C++14 needed). Includes BioConductor 3.13.0 # This is the recommended version. module load apps/gcc/R/3.6.1-gcc830 # incline256 boxes only module load apps/gcc/R/3.6.1 # any incline node type (but user-packages may not # install if C++11 needed) module load apps/gcc/R/3.6.0 # incline256 boxes only module load apps/gcc/R/3.5.2 # incline256 boxes only 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
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):
- 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
- Start R in the usual way (choose the version of R you require):
module load apps/gcc/R/3.2.0 R
- 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
- Select a UK mirror when prompted.
- Note, you may have to select a mirror name that does not have
[https]
next to it.
- Note, you may have to select a mirror name that does not have
- Then to use the package in R, load the library in R:
library(thing)
nloptr dependency
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 apps/gcc/R/4.3.1 module load libs/gcc/nlopt/2.7.1 R install.packages("nloptr")
Rcpp dependency
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 apps/gcc/R/4.3.1 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):
- 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')
- 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):
- Add the University Web proxy to your
~/.Renviron
file (create the file if you don't already have one). Note: R will not read environment variables - you must use the~/.Renviron
file:http_proxy=http://proxy.man.ac.uk:3128
- NB: The easiest way to add to or create a new file is to do the following once logged in to Redqueen:
echo http_proxy=http://proxy.man.ac.uk:3128 >> ~/.Renviron
- NB: The easiest way to add to or create a new file is to do the following once logged in to Redqueen:
- Now load a version of R that has bioconductor installed, e.g.
module load apps/gcc/R/3.2.0
- 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
- 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 ------
- 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
- 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 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 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