R is a software environment for statistical computing. RStudio is a graphical IDE for R.
Libraries
A large number of additional libraries from CRAN and Bioconductor are installed and ready to use.
You can see the list of currently installed libraries by executing R's library()
or installed.packages()
methods.
You can install additional libraries into your home directory yourself. Just use the install.packages()
method. The first time you try to do this you will be prompted to
create a personal library, enter yes. Your libraries will be installed into ~/R/x86_64-pc-linux-gnu-library/x.y where x and y are the R major and minor version numbers
respectively. When a new R version is used you will need to reinstall any additional libraries for that version.
> install.packages("ape")
Warning in install.packages("ape") :
'lib = "/cm/shared/apps/R/4.3.1/lib64/R/library"' is not writable
Would you like to use a personal library instead? (yes/No/cancel) yes
Would you like to create a personal library
‘/alice-home/1/n/nye1/R/x86_64-pc-linux-gnu-library/4.3’
to install packages into? (yes/No/cancel) yes
Example submission script
Below is an example of a job submission script which will execute the R program example.R. Remember to set the account name to the ALICE project you wish to use, or omit the
--account
option altogether if you are not in any ALICE projects.
#SBATCH --job-name=R_job
#SBATCH --account=project
#SBATCH --time=01:00:00
#SBATCH --cpus-per-task=1
#SBATCH --mem=8g
#SBATCH --export=NONE
# Load the R module
module load R/4.3.1
# Work from the job submission directory
cd $SLURM_SUBMIT_DIR
R --vanilla -s -f example.R
An alternative to using R -f example.R
is R CMD BATCH example.R
. The main difference is that in the first form the output will be captured by the scheduler into a job-specific
file, and in the second form R will redirect the output to the file example.Rout. The first form is better especially if an array job is being run.
RStudio
In order to use RStudio, ensure any available R module is loaded, then use the command rstudio
to start it. Obviously a display will be required, so RStudio should only be started within a NoMachine session. In an interactive job you need to ensure you have X-forwarding enabled with the --x11 argument to srun.