Attachments
module load RThe command
R --version
returns the version of R you have loaded:R --versionThe command
R version 3.5.1 (2018-07-02) -- "Feather Spray" Copyright (C) 2018 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit)
which R
returns the location where the R executable resides:which RNote: if you use an ~/.Rprofile file, it should be independent of the version of R, i.e. library paths should NEVER be set within this file.
/project/cacds/apps/easybuild/software/R/3.5.1-intel-2017b-X11-20171023/bin/R
srun -A #Allocation_AWARD_ID --pty /bin/bash -l
module load RThere are several ways to launch an R script on the command line:
Rscript yourfile.R
R CMD BATCH yourfile.R
R --no-save
./yourfile2.R
Rscript
command) redirects the output into stdout. The second approach (i.e. using the R CMD BATCH
command) redirects its output into a file (in case yourfile.Rout
). A third approach is to redirect the input of the file yourfile.R
to the R executable. Note that in the latter approach you must specify one of the following flags: --save
, --no-save
or --vanilla.
yourfile2.R)
need to be altered (-> executable)commandArgs()
function, e.g., if we have a script called myScript.R
:## myScript.R
args <- commandArgs(trailingOnly =TRUE)
rnorm(n=as.numeric(args[1]), mean=as.numeric(args[2]))
then we can call it with arguments as e.g.:Rscript myScript.R 5 100
[1] 101.35122 100.60181 100.54685 98.13926 99.19416
runR.slurm
(see attachment). For demonstration purposes we are using the same myScript.R
as above. #!/bin/bash #SBATCH --time=00:10:00 # Walltime #SBATCH --nodes=1 # Use 1 Node (Unless code is multi-node parallelized) #SBATCH --ntasks=1 # We only run one R instance = 1 task #SBATCH --cpus-per-task=12 # number of threads we want to run on #SBATCH -o slurm-%j.out-%N #SBATCH --mail-type=ALL #SBATCH --mail-user=$USER@uh.edu # Your email address #SBATCH --job-name=myrjob # Load R (default version) module load R # Run the R script in batch Rscript myScript.R 5 100 echo "End of program at `date`"We then submit our job via the
sbatch
commnd to SLURM.sbatch runR.slurmYour job will be scheduled, you receive a short message about the submission and the job will eventually run. All output will be stored in a file called slurm-[jobid].out.
setenv OMP_NUM_THREADS 1 # Tcsh/Csh Shellto facilitate easier use of parallel independent calculations. If you want to run R in a multithreaded fashion (e.g. on a compute node), we strongly recommend not to use more threads than there are physical cores on the node.
export OMP_NUM_THREADS=1 # Bash Shell
.libPaths()
returns the names of the libraries (directories) which are accessible to the R executable which has been loaded in your environment..Library
command. Among the packages in this library we have "base", "datasets", "utils", etc.R
> .Library
[1] "/project/cacds/apps/easybuild/software/R/3.5.1-intel-2017b-X11-20171023/lib64/R/library"
R > .libPaths() [1] "/home/usertest/local/R_libs" [2] "/project/cacds/apps/easybuild/software/R/3.5.1-intel-2017b-X11-20171023/lib64/R/library"
install.packages()
(invoked within R)R CMD INSTALL
(invoked from a Linux Shell)install.packages()
RThe
>library(maRketSim)
Error in library(maRketSim) : there is no package called ‘maRketSim’
>install.packages(c("maRketSim"),
lib=c(paste("/home/usertest/local",Sys.getenv("USER"),"/RLibs/",Sys.getenv("R_VERSION"),sep="")),
repos=c("http://cran.us.r-project.org"),verbose=TRUE)
>library(maRketSim)
library($PACKAGE)
function tries to load a package $PACKAGE
. If R can't find it an error will be printed on stdout. The install.packages()
function has several flags. The lib
flag needs to be followed by the directory where you want to install the package (should be $R_LIBS_USER
). From the installation output we notice that the install.packages()
function calls the low-level installation command (R CMD INSTALL
). This command will be discussed in the next section.lib
flag can be also used with other repository packages, e.g. with Bioconductor. As we have some Bioconductor packages installed in our default location, use also lib.loc
flag to tell Bioconductor to tell where the "original" Bioconductor location is:source("https://bioconductor.org/biocLite.R")
biocLite(pkgs, lib.loc = "/home/$USER/local/RLibs/$R_VERSION", lib="/home/$USER/local/RLibs/$R_VERSION")
module load intel netcdf-c udunits
export PATH=$NETCDFC/bin:$PATH (or in tcsh shell, setenv PATH $NETCDFC/bin:$PATH)
export PATH=$UDUNITS/bin:$PATH (or in tcsh shell, setenv PATH $UDUNITS/bin:$PATH)
wget https://cran.r-project.org/src/contrib/RNetCDF_1.9-1.tar.gz
R CMD INSTALL --library=/uufs/chpc.utah.edu/common/home/$USER/RLibs/$R_VERSION \
--configure-args="CPPFLAGS='-I$UDUNITS/include'\
LDFLAGS='-Wl,-rpath=$NETCDFC/lib \
-L$NETCDFC/lib -lnetcdf \
-Wl,-rpath=$UDUNITS/lib\
-L$UDUNITS/lib -ludunits2 ' \
--with-nc-config=$NETCDFC/bin/nc-config " RNetCDF_1.9-1.tar.gz
R CMD INSTALL
calls ./configure
under the hood. The best way to tackle such an installation is to download the tar.gz file first, find the appropriate installation flags (different for each package!) and then feed those flags to the R CMD INSTALL
command./project/cacds/apps/easybuild/software/icc/2017.8.262-GCC-6.4.0-2.28/compilers_and_libraries_2017.8.262/linux/include/complex(310): error #308: member "std::complex::_M_value" (declared at line 1337 of "/usr/include/c++/4.8.5/complex") is inaccessibleThe workaround this is to disable this diagnostic error by creating (or modifying) file
return __x / __y._M_value;
~/.R/Makevars
such as:CFLAGS += -wd308
CXXFLAGS += -wd308
CPPFLAGS += -wd308
PKG_CFLAGS += -wd308
PKG_CXXFLAGS += -wd308
PKG_CPPFLAGS += -wd308
Please wait... it will take a second!