R logo

 

 

There are various versions of R available on Grace, available through the module command:

$ module avail R
--------------------------- /gpfs/grace/modules/apps -------------------------------------------
R/2.12        R/2.13        R/2.13-OMPI   R/2.13.1      R/2.15.0      R/2.15.0-ompi R/2.15.1

Using R

To start R in an interactive session, simply load the R module required, and then type R

To submit an R task to run as a batch job, create a batch job script similar to the following:

#!/bin/sh
#BSUB -q short
#BSUB -J R_job
#BSUB -oo RJob-%J.out
#BSUB -eo RJob-%J.err
. /etc/profile
module add R/2.15.1
R CMD BATCH Random.R

This is then submitted with the following command (assuming your script is called RJob.bsub):

[cc@cn093 ~]$ bsub < RJob.bsub
Job <2263821> is submitted to queue <short>.

List Installed Packages

To see what packages are installed for the version of R you are using, use the library command, which will list packages by their install location:

> library()
Packages in library ‘/gpfs/grace/R-2.15.1/lib64/R/lib':

abind                   Combine multi-dimensional arrays
<SNIP>
zoo                     S3 Infrastructure for Regular and Irregular
                        Time Series (Z's ordered observations)

Packages in library ‘/gpfs/sys/cc/R/x86_64-unknown-linux-gnu-library/2.15':

R.matlab                Read and write of MAT files together with
                        R-to-Matlab connectivity
R.oo                    R object-oriented programming with or without
                        references

Packages in library ‘/gpfs/grace/R-2.15.1/lib64/R/library':

base                    The R Base Package
boot                    Bootstrap Functions (originally by Angelo Canty
                        for S)
<SNIP>
utils                   The R Utils Package

Installing Packages

If you need an additional package installed, you can either contact hpc.admin@uea.ac.uk with the details of the package and the version of R you require it for,and we will look to install it for you into the global package library and it will be available to all users.

Alternatively, you can install R packages into your own personal library.  Within R run the install.packages command with the package you wish to install.  For example, to install the R.matlab package run install.package("R.matlab").  Because you don't have permission to write to the global package library, you will be prompted to use a personal library instead.  If a personal library doesn't already exist, you will be prompted to create a personal library:

> install.packages("R.matlab")
Installing package(s) into ‘/gpfs/grace/R-2.15.1/lib64/R/lib'
(as ‘lib' is unspecified)
Warning in install.packages("R.matlab") :
  'lib = "/gpfs/grace/R-2.15.1/lib64/R/lib"' is not writable
Would you like to use a personal library instead?  (y/n) y
Would you like to create a personal library
~/R/x86_64-unknown-linux-gnu-library/2.15
to install packages into?  (y/n) y

After confirming the location of the personal library, you will be prompted for a CRAN (Comprehensive R Archive Network) download location, either from a text or graphical list.  Select a location in the UK.

--- Please select a CRAN mirror for use in this session ---
CRAN mirror
<SNIP>
71: Turkey                       72: UK (Bristol)
73: UK (London)                  74: UK (St Andrews)
<SNIP>
Selection: 72

R will attempt to download and install any dependency packages required, for example for R.matlab, R.oo is required:

also installing the dependency ‘R.oo'

trying URL 'http://www.stats.bris.ac.uk/R/src/contrib/R.oo_1.13.0.tar.gz'
Content type 'application/x-gzip' length 388979 bytes (379 Kb)
opened URL
==================================================
downloaded 379 Kb

trying URL 'http://www.stats.bris.ac.uk/R/src/contrib/R.matlab_1.7.0.tar.gz'
Content type 'application/x-gzip' length 86578 bytes (84 Kb)
opened URL
==================================================
downloaded 84 Kb

* installing *source* package ‘R.oo' ...
** package ‘R.oo' successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded

* DONE (R.oo)
* installing *source* package ‘R.matlab' ...
** package ‘R.matlab' successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
Warning in setGenericS3.default(name, export = exportGeneric, envir = envir,  :
  Renamed the preexisting function getOption to getOption.default, which was defined in environment base.
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded

* DONE (R.matlab)

The downloaded source packages are in
        ‘/tmp/RtmpiU6Ttu/downloaded_packages'
>

Load Specific Package

If you have installed your own version of a package, you can have R use a specific version by specifying the library to load the package from (in my case /gpfs/sys/cc/R/x86_64-unknown-linux-gnu-library/2.15/ is the default location R used in the example above):

> library("R.matlab", lib.loc="/gpfs/sys/cc/R/x86_64-unknown-linux-gnu-library/2.15/")

Uninstalling Packages

You can use the remove.packages command to uninstall a package from your own library.  To remove a package you need to tell remove.package which package you wish to remove, and the library you wish to remove it from:

> remove.packages("R.matlab","/gpfs/sys/cc/R/x86_64-unknown-linux-gnu-library/2.15/")
> remove.packages("R.oo","/gpfs/sys/cc/R/x86_64-unknown-linux-gnu-library/2.15/")