R

Software name: 
R
Policy 

R is produced by the R Development Core Team, is freely available and open source, licensed under the GNU General Public Licence

General 

R is `GNU S' - A language and environment for statistical computing and graphics. R is similar to the award-winning S system, which was developed at Bell Laboratories by John Chambers et al. It provides a wide variety of statistical and graphical techniques (linear and nonlinear modelling, statistical tests, time series analysis, classification, clustering, ...).

Description 

R is designed as a true computer language with control-flow constructions for iteration and alternation, and it allows users to add additional functionality by defining new functions. For computationally intensive tasks, C, C++ and Fortran code can be linked and called at run time.

S is the statistician's Matlab and R is to S what Octave is to Matlab.

Availability 

On HPC2N we have R available as a module on Kebnekaise. The system installed version is available in the path on Abisko.

Usage at HPC2N 

Abisko

R is available by default in your PATH, so there is no special setup necessary.

Kebnekaise

To use the R module, first add it to your environment. Use:

module spider R

to see which versions are available and how to load the module and the needed prerequisites.

Example, loading R version 3.3.1

ml icc/2017.1.132-GCC-6.3.0-2.27
ml ifort/2017.1.132-GCC-6.3.0-2.27
ml impi/2017.1.132
ml R/3.3.1

NOTE: As in the example above, in order to load R, you need to load all the modules mentioned on both lines (when doing ml spider R/3.3.1), not just one of them (error in the description from easybuild).

You can read more about loading modules on our Accessing software with Lmod page and our Using modules (Lmod) page.

Packages installed

  • Start R
  • At the R prompt, enter these four lines:
    ip <- as.data.frame(installed.packages()[,c(1,3:4)])
    
    rownames(ip) <- NULL
    
    ip <- ip[is.na(ip$Priority),1:2,drop=FALSE]
    
    print(ip, row.names=FALSE)
  • After the last enter, you will get a list of R packages and versions that
    are installed.

Running

Serial job

In order to run R from the batch system you need to pass a few extra parameters to R. This example submit file should get you started:

#!/bin/bash
### SNAC project number, enter your own
#SBATCH -A SNICXXXX-YY-ZZ 
# Asking for one core
#SBATCH -n 1
#SBATCH --time=00:10:00

# Serial job
# No matter how many processers you request this job will run
# on _only_ one core.

# If you are running on Kebnekaise, load the module first. This is not 
# needed on Abisko. 
ml icc/2017.1.132-GCC-6.3.0-2.27
ml ifort/2017.1.132-GCC-6.3.0-2.27
ml impi/2017.1.132
ml R/3.3.1

# Run R in batch mode. Use input.R as input file and
# store output in Rexample.out

R --no-save --quiet < input.R > Rexample.out

Parallel job

Kebnekaise

Rmpi is installed. In order to use it, you need to load the library and use a submission script.

Abisko

Rmpi is NOT installed and you need to build it yourself and then load the library. See our page "User Installed Software - R" for more information. You need to use a submission script to run with Rmpi when you have built it.

Note for both:

  • you must NOT spawn slaves with mpi.spawn.Rslaves()!
  • You must use "mpirun R" in your script.

Here is an example submit script (you need to load the Rmpi library in your R script)

#!/bin/bash
#SBATCH -A SNICXXXX-YY-ZZZ
# Asking for 8 cores - you can pick more or less, depending on what you need
#SBATCH -n 8
# Asking for 30 min run time - change to fit what you need
#SBATCH --time=00:30:00

# Load the R module if you are on Kebnekaise
ml icc/2017.1.132-GCC-6.3.0-2.27
ml ifort/2017.1.132-GCC-6.3.0-2.27
ml impi/2017.1.132
ml R/3.3.1

mpirun R -q -f <program>.R

Adding R modules

To add R modules not installed on our system see our documentaion on installing R modules in your own account.

Extending R

Please see the R documentation for information on how to extend R by creating your own packages. Writing R Extensions is a comprehensive guide and is highly recommended.

Additional info 
Updated: 2017-11-22, 19:57