Support - Software - Application programs: R

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 on Abisko and Akka.

Usage at HPC2N

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

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:
Akka:

#!/bin/sh
### SNAC project number, enter if applicable.
### NOTE! No spaces or slashes allowed
###PBS -A SNICXXX-YY-ZZ
### Job name - defaults to name of submit script
#PBS -N Rexample
### Output files - defaults to jobname.[eo]jobnumber
#PBS -e Rexample.err
### Mail on - a=abort, b=beginning, e=end - defaults to a
#PBS -m ae
### Number of nodes - defaults to 1:1
### Requesting 1 nodes with 2 VP:s on each node
#PBS -l nodes=1:ppn=2
### Requesting time - 10 minutes
#PBS -l walltime=00:10:00 

# Change to Working Directory
cd $PBS_O_WORKDIR

# Serial job
# No matter how many processers you request this job will run 
# on _only_ one node. Though you should be alone on it.

# 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

Abisko:

#!/bin/sh
### SNAC project number, enter if applicable.
### NOTE! No spaces or slashes allowed
###PBS -A SNICXXX-YY-ZZ
#SBATCH -A sysop
### Job name - defaults to name of submit script
#iSBATCH -J my_r_job
### Output files - defaults to jobname.[eo]jobnumber
#SBATCH -o rjob.%j.out
# Number of nodes - asking one node, and the default 1 socket (12 cores)  
#SBATCH -N 1
#SBATCH --time=00:10:00

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

# 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

R igraph module

igraph is a free software package for creating and manipulating undirected and directed graphs. It includes implementations for classic graph theory problems like minimum spanning trees and network flow, and also implements algorithms for some recent network analysis methods, like community structure search.

On HPC2N it is installed on Akka. You access it by loading the module

module load igraph

and then adding it after starting R

> library(igraph)

There are some online documentation for igraph here, and a few examples here.

Adding R modules

To add R modules not installed on our system but available in CRAN, adapt the following example of installing ash to your needs:

  • Extract the downloaded package:
    tar -xzf /tmp/ash_1.0-9.tar.gz
    
  • Tell R to install it into the subdirectory lib:
    R CMD INSTALL -l /pfs/nobackup$HOME/R-packages ash
    
  • To use the newly installed package you need to add the path to the package to R_LIBS, either by setting it in .Renviron, i.e create a file ~/Public/.Renvironand add:
    R_LIBS="/pfs/nobackup$HOME/R-packages"
    

    and create a soft-link from it to your home-directory:

    ln -s ~/Public/.Renviron ~/
    

    NOTE: You can't use $HOMEin ~/.Renviron. You have to replace it with the value of $HOME. (run 'echo $HOME' to get the value)

For more information about installing and using your own packages see How can add-on packages be installed and How can add-on packages be used?.

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