Programming/R
Contents
Programming Details
R is a programming language and software environment for statistical analysis, graphics representation and reporting.
R is freely available under the GNU General Public License, and can be loaded as a module on Viper (with Linux), Windows (PC) and Mac.
Programming example
x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131) y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48) # Apply the lm() function. relation <- lm(y~x) print(relation)
Modules Available
The following modules are available:
- module add R/3.4.1
Batch Mode
The SLURM batch file would typical look like the one below, in this case it would be named 'rscript.job'.
#!/bin/bash #SBATCH -J compute-single-node #SBATCH -N 1 #SBATCH --ntasks-per-node 1 #SBATCH -D /home/pysdlb/CODE_SAMPLES/R #SBATCH -o %N.%j.%a.out #SBATCH -e %N.%j.%a.err #SBATCH -p compute echo $SLURM_JOB_NODELIST module purge module add R/3.4.1 export I_MPI_DEBUG=5 export I_MPI_FABRICS=shm:tmi export I_MPI_FALLBACK=no Rscript r.rsc
To run this on the cluster you would need to invoke the command sbatch rscript.job
Interactive Mode
The program is interpreted by the R runtime program, so compilation does not apply here.
[username@login01 ~]$ module add R/3.4.1 [username@login01 ~]$ R R version 3.4.1 (2017-06-30) -- "Single Candle" Copyright (C) 2017 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. >
Libraries
To show the libraries included type ( within R ) the command : library()
Packages in library ‘/trinity/clustervision/CentOS/7/apps/R/3.3.0/lib64/R/library’: base The R Base Package boot Bootstrap Functions (Originally by Angelo Canty for S) class Functions for Classification cluster "Finding Groups in Data": Cluster Analysis Extended Rousseeuw et al. codetools Code Analysis Tools for R colorspace Color Space Manipulation compiler The R Compiler Package datasets The R Datasets Package dichromat Color Schemes for Dichromats digest Create Compact Hash Digests of R Objects foreign Read Data Stored by Minitab, S, SAS, SPSS, Stata, Systat, Weka, dBase, ... ggplot2 Create Elegant Data Visualisations Using the Grammar of Graphics
Installing Additional Libraries
If you need an additional library installed that would be used by more than just yourself, contact the Viper team on help@hull.ac.uk with the details of the library and the version of R you require it for.
Alternatively, you can install a R library into your own personal library. Within R run the install.packages command with the package you wish to install.
> install.packages("R.matlab") Warning in install.packages("R.matlab") : 'lib = "/trinity/clustervision/CentOS/7/apps/R/3.3.0/lib64/R/library"' 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-pc-linux-gnu-library/3.3 to install packages into? (y/n) y --- Please select a CRAN mirror for use in this session --- HTTPS CRAN mirror 1: 0-Cloud [https] 2: Algeria [https] 3: Australia (Canberra) [https] 4: Australia (Melbourne) [https] 5: Australia (Perth) [https] 6: Austria [https] 7: Belgium (Ghent) [https] 8: Brazil (RJ) [https] 9: Brazil (SP 1) [https] 10: Bulgaria [https] 11: Canada (MB) [https] 12: Chile 1 [https] 13: Chile 2 [https] 14: China (Beijing) [https] 15: China (Hefei) [https] 16: China (Lanzhou) [https] 17: Colombia (Cali) [https] 18: Czech Republic [https] 19: Denmark [https] 20: France (Lyon 1) [https] 21: France (Lyon 2) [https] 22: France (Marseille) [https] 23: France (Montpellier) [https] 24: France (Paris 2) [https] 25: Germany (Münster) [https] 26: Iceland [https] 27: India [https] 28: Indonesia (Jakarta) [https] 29: Ireland [https] 30: Italy (Padua) [https] 31: Japan (Tokyo) [https] 32: Malaysia [https] 33: Mexico (Mexico City) [https] 34: New Zealand [https] 35: Norway [https] 36: Philippines [https] 37: Russia (Moscow) [https] 38: Serbia [https] 39: Spain (A Coruña) [https] 40: Spain (Madrid) [https] 41: Sweden [https] 42: Switzerland [https] 43: Taiwan (Chungli) [https] 44: Turkey (Denizli) [https] 45: Turkey (Mersin) [https] 46: UK (Bristol) [https] 47: UK (Cambridge) [https] 48: UK (London 1) [https] 49: USA (CA 1) [https] 50: USA (IA) [https] 51: USA (IN) [https] 52: USA (KS) [https] 53: USA (MI 1) [https] 54: USA (OR) [https] 55: USA (TN) [https] 56: USA (TX 1) [https] 57: USA (TX 2) [https] 58: (HTTP mirrors) Selection: 48 also installing the dependencies ‘R.methodsS3’, ‘R.oo’, ‘R.utils’ trying URL 'https://cran.ma.imperial.ac.uk/src/contrib/R.methodsS3_1.7.1.tar.gz' Content type 'unknown' length 25731 bytes (25 KB) ================================================== downloaded 25 KB trying URL 'https://cran.ma.imperial.ac.uk/src/contrib/R.oo_1.21.0.tar.gz' Content type 'unknown' length 403410 bytes (393 KB) ================================================== downloaded 393 KB trying URL 'https://cran.ma.imperial.ac.uk/src/contrib/R.utils_2.5.0.tar.gz' Content type 'unknown' length 389402 bytes (380 KB) ================================================== downloaded 380 KB trying URL 'https://cran.ma.imperial.ac.uk/src/contrib/R.matlab_3.6.1.tar.gz' Content type 'unknown' length 109818 bytes (107 KB) ================================================== downloaded 107 KB * installing *source* package ‘R.methodsS3’ ... ** package ‘R.methodsS3’ successfully unpacked and MD5 sums checked ** R ** inst ** preparing package for lazy loading ** help *** installing help indices ** building package indices ** testing if installed package can be loaded * DONE (R.methodsS3) * 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 ** testing if installed package can be loaded * DONE (R.oo) * installing *source* package ‘R.utils’ ... ** package ‘R.utils’ 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 warnings to warnings.default, which was defined in environment base. ** help *** installing help indices ** building package indices ** testing if installed package can be loaded * DONE (R.utils) * installing *source* package ‘R.matlab’ ... ** package ‘R.matlab’ successfully unpacked and MD5 sums checked ** R ** inst ** byte-compile and prepare package for lazy loading ** help *** installing help indices ** building package indices ** testing if installed package can be loaded * DONE (R.matlab) The downloaded source packages are in ‘/tmp/RtmpO7iqto/downloaded_packages’