The default version of R that is installed in the cluster operating system is 3.5.2.
Version 4.1.3 is also installed with many packages and can be loaded with the module command.
module load R4
This is the preferred version to work with in the cluster.
Packages may be distributed in source form or compiled binary form. Installing source packages which contain C/C++/Fortran code requires that compilers and related tools be installed. Binary packages are platform-specific and generally need no special tools to install, but see the documentation for your platform for details.
For most users it suffices to call install.packages(pkgname)
or its GUI equivalent if the intention is to install a CRAN package and internet access is available. On most systems ‘install.packages()’ will allow packages to be selected from a list box (typically with thousands of items).
Packages can be downloaded and installed from within R. First choose your nearest CRAN mirror using chooseCRANmirror()
. Then download and install packages pkg1 and pkg2 by
> install.packages(c("pkg1", "pkg2"))
The essential dependencies of the specified packages will also be fetched.
Unless the library is specified (argument lib
) the first library in the library search path is used: if this is not writable, R will ask the user (in an interactive session) if the default personal library should be created, and if allowed to will install the packages there.
Calling the .libPaths()
function will show all the package locations (user,site,global), and can be used to change the user-path by adding the new
argument and calling .libPaths("My/New/Path/For/Packages")
. Note that the path must exist and be writable for the change to take place.
If you need to change the default (user) path, you can do so by setting the "R_LIBS_USER"
environment variable in a script or in your .cshrc/.bashrc files.
If you want to fetch a package and all those it depends on (in any way) that are not already installed, use e.g.
> install.packages("Rcmdr", dependencies = TRUE)
To run R scripts you need to use this line as the shebang in your script:
#!/usr/bin/env Rscript
This way it will use either the R installed in the operating system or R version 4.1 if you used module command to load it.
Then you can make your R script executable and run it:
chmod +x myRscript.R
./myRscript.R
Or run it with Rscript command:
Rscript myRscript.R
Ensure that the environment variable TMPDIR
is either unset (and /tmp exists and can be written in and executed from) or is the absolute path to a valid temporary directory, not containing spaces.
R creates a folder under /tmp/ if none of these environment variables are configured - TMPDIR
, TMP
and TEMP
. Because there is a limit on how much space each user can have in the /tmp/ folder on all nodes, you might run into issues using R.
If your job fails with this error: Fatal error: cannot create 'R_TempDir', or you know that your R script will use a lot of space in /tmp/ then configure one of the above environment variables to a location in any of your lab folders.
For bash (sh) shell:
export TMPDIR=/path/to/your/tmp/r/folder
And for csh shell:
setenv TMPDIR /path/to/your/tmp/r/folder
Remember to clear (if necessary) the contents of the folder you configured after your R script has finished.
There is a Singularity image on the cluster with Rstudio Server. You can run it and connect to it from any browser that is installed on your PC.
To work with it download the rstudio_server.sh
You can change run time, number of cores and amount of memory by updating these lines in the script:
#SBATCH --time=
#SBATCH -n
#SBATCH --mem=
Leave the rest of the script as is!
Submit the script with this command:
sbatch rstudio_server_sbatch_script.sh
Once the job is running you need to look inside the Slurm out file.
The default name of Slurm output file is slurm-<jobid>.out and it is created by default in the same directory that you were in when submitting the job with sbatch.
You can use this command:
cat slurm-jobid.out
You will see instructions on how to open a tunnel to the cluster.
If you are working with Linux or Mac then copy the tunnel command and paste it in a new terminal window or tab.
If you are working with Mobaxterm on Windows then start a local terminal in Mobaxterm and paste the command inside it.
After entering OTP password and IDNG (Unix) password open a browser on your PC and paste this URL:
http://localhost:8787