R

Z MetaCentrum
Přejít na: navigace, hledání


Description

R is a language and environment for statistical computing and graphics. R provides a wide variety of statistical (linear and nonlinear modelling, classical statistical tests, time-series analysis, classification, clustering, ...) and graphical techniques, and is highly extensible. R is an integrated suite of software facilities for data manipulation, calculation and graphical display. R includes

  • an effective data handling and storage facility,
  • a suite of operators for calculations on arrays, in particular matrices,
  • a large, coherent, integrated collection of intermediate tools for data analysis,
  • graphical facilities for data analysis and display either on-screen or on hardcopy and printed version.
  • a well-developed, simple and effective programming language which includes conditionals, loops, user-defined recursive functions and input and output facilities.

See R View about High-Performance and Parallel Computing with R

Availability

  • Module R-3.4.0-gcc: R version 3.4.0
  • Module R-3.3.1-intel: R version 3.3.1 with blas, lapack and tcltk support
  • Module R-3.2.3-intel: R version 3.2.3 with blas, lapack and tcltk support
  • Module R-3.1.1: R version 3.1.1 with blas, lapack and tcltk support
  • Module R-3.1.0: R version 3.1.0 with blas and lapack support
  • Module R-3.0.1: R version 3.0.1 with blas and lapack support
  • Module R-2.14.0: R version 2.14.0
  • Module R-2.8.1: R version 2.8.1

Use

Initialize environment and run R

module add R-3.4.0-gcc
R

for batch regime, use your R file (commands.R) with commands for R

R CMD BATCH commands.R

Notice: This application use or needs GUI – graphical interface. To use the application in graphical mode see Remote desktop or X-Window.

Using Rmpi

How to use the Rmpi package? At first prepare a file hello_world_rmpi.R which will contain the following example (adopted from http://math.acadiau.ca/ACMMaC/Rmpi/sample.html):

# Load the R MPI package if it is not already loaded.
if (!is.loaded("mpi_initialize")) {
    library("Rmpi")
    }
# Spawn as many slaves as possible
mpi.spawn.Rslaves()
# In case R exits unexpectedly, have it automatically clean up
# resources taken up by Rmpi (slaves, memory, etc...)
.Last <- function(){
    if (is.loaded("mpi_initialize")){
        if (mpi.comm.size(1) > 0){
            print("Please use mpi.close.Rslaves() to close slaves.")
            mpi.close.Rslaves()
        }
        print("Please use mpi.quit() to quit R")
        .Call("mpi_finalize")
    }
}
# Tell all slaves to return a message identifying themselves
mpi.remote.exec(paste("I am",mpi.comm.rank(),"of",mpi.comm.size()))
# Tell all slaves to close down, and exit the program
mpi.close.Rslaves()
mpi.quit()

Add the openmpi modul and run the batch in "R"

module add R openmpi-1.6.5-intel
export OMPI_MCA_btl=sm,tcp,self
export OMPI_UNIVERSE_SIZE=`expr $TORQUE_RESC_TOTAL_PROCS - 1`
mpirun R CMD BATCH hello_world_rmpi.R

Notice: This application supports parallel computing (MPI, OpenMP) which can have weird consequences. For more details about parallel computing visit the page How to compute/Parallelization.

UTF-8 support

This command sets the support for utf-8 at the beginning of the R script. For example where you need to import the Czech diacritics by function read.csv():

Sys.setlocale(category = "LC_ALL", locale = "en_US.UTF8")

Documentation

Documentation is available on WWW server or locally in program directory.

Supported platforms

Different versions of Unix, Windows, MacOS.

Program administrator

meta@cesnet.cz

Homepage

URL: http://www.r-project.org/

FAQ (usefull links)

  • Everyone can easily create own R packages library, you just need some folder (ideally on the /storage tree), eg.
/storage/brno6/home/$LOGNAME/Rpackages/

($LOGNAME is your login in MetaCentrum). Than you can install package by

>install.packages("PACKAGE_NAME",lib="/storage/brno6/home/$LOGNAME/Rpackages/")

and load of such package

>library(PACKAGE_NAME,lib.loc="/storage/brno6/home/$LOGNAME/Rpackages/")

To set the directory as default, you need to set R_LIBS variable before running R, eg.

export R_LIBS="/storage/brno6/home/$LOGNAME/Rpackages"

To check installation path, you just run R a .libPaths() function and now you do not need to specify location of the directory with your own packages any more

R
> .libPaths()
[1] "/auto/brno6/home/$LOGNAME/Rpackages"
[2] "/afs/ics.muni.cz/software/R-3.1.0/lib/R/library"
> install.packages("PACKAGENAME")
> library("PACKAGENAME")
  • simple one core R script
#PBS -N helloR
#PBS -l walltime=2:00:00
#PBS -l select=1:ncpus=1:mem=4gb:scratch_local=10gb

#clean scratch after the end
trap 'clean_scratch' TERM EXIT

#INPUT directory - with R script and other inputs
MYIN=/storage/brno6/home/$LOGNAME/helloR
#INPUT R script
MYR=hello.R
#OUTPUT directory - where to store results
MYOUT=/storage/brno6/home/$LOGNAME/helloRout
mkdir -p $MYOUT

module add R-4.0-gcc
# go to scratch directory
cd $SCRATCHDIR || exit 2 
# copy all files from $MYIN
cp $MYIN/* .

R -q --vanilla < $MYR > $MYR.output
#copy everything to MYOUT
cp * $MYOUT/

script is send for computation by command

qsub helloR.sh