documentation:software:r

If you have a R script called job.r, you can run it from your submit script with the following command:

R CMD BATCH -q job.r job.out

The job.out determines where printed output from job.r goes. If you have multiple jobs running at the same time this will cause your jobs to overwrite each others output. In this case, replace the command with the following:

R CMD BATCH -q job.r job.${PBS_JOBID/.*}.out

which will place the output in files called job.$JOBNUMBER.out

If you create a job.r with the following contents:

#!/usr/bin/Rscript
print("Hello Batch World!")

To run the script with Rscript, we must first authorize the file:

$ chmod +x  job.r

Then, we can either run the file with:

$ Rscript job.r

Or:

$ ./job.r

Doing so will produce output directly in the terminal, e.g.

$ Rscript job.r
[1] "Hello Batch World!"

You can install packages from CRAN yourself by using the following R command:

install.packages(c("gamlss"), dependencies=TRUE, repos='http://cran.rstudio.com/')

replacing gamlss with your own list of package names.

You can list the installed packages with the command:

installed.packages()

rJava

You can install package rJava from CRAN yourself by using the following R command: Login into submit node, and preform the following:

Enter an interactive job.

[user@submitnew ~]$ qsub -I
qsub: waiting for job xxxxx.maui.grid.fe.up.pt to start
qsub: job xxxxx.maui.grid.fe.up.pt ready

Configure java environment for R

[user@compute-node ~]$ R CMD javareconf -e
Java interpreter : /bin/java
Java version     : 1.8.0_191
Java home path   : /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.el7_5.x86_64/jre
Java compiler    : /bin/javac
Java headers gen.: /bin/javah
Java archive tool: /bin/jar
 
trying to compile and link a JNI program 
detected JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/linux
detected JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
gcc -m64 -std=gnu99 -I"/usr/include/R" -DNDEBUG -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.el7_5.x86_64/jre/../include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.el7_5.x86_64/jre/../include/linux  -I/usr/local/include   -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic  -c conftest.c -o conftest.o
gcc -m64 -std=gnu99 -shared -L/usr/lib64/R/lib -Wl,-z,relro -o conftest.so conftest.o -L/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.el7_5.x86_64/jre/lib/amd64/server -ljvm -L/usr/lib64/R/lib -lR
 
The following Java variables have been exported:
JAVA_HOME JAVA JAVAC JAVAH JAR JAVA_LIBS JAVA_CPPFLAGS JAVA_LD_LIBRARY_PATH
Running: /bin/bash

Start R

[user@compute-node ~]$ R
R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-redhat-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.
 
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.
 
>

In the R command line preform

install.packages(c("rJava"), dependencies=TRUE, repos='http://cran.rstudio.com/')
  • documentation/software/r.txt
  • Last modified: 2019/01/09 17:54
  • by tsmorais