Runing R in Marvin Cluster

Independently of RStudio, Marvin cluster can also run R files. For example, here we have a simple r code we can run on the cluster:

a <- 5

b <- 2

print(a*b)

 

As we can suppose, the output we expect is 10.

 

Save the code as an r file (your_code.r) and proceed on creating a sbatch file, it should follow the next structure:

#!/bin/bash

#SBATCH --job-name=test

#SBATCH --cpus-per-task=1

#SBATCH --mem-per-cpu=8G

#SBATCH --mail-type=END

#SBATCH [email protected]

 

module load R/X.X.X  # choose the module that you need (module av to see available modules)

Rscript yourRscript.r

 

Save it as a sbatch file (sbatch_example.sh), and upload it to your cluster account using an application such as FileZilla (for macOS and windows), or uploading it from your terminal if you are working with linux/ubuntu using the command:

$ scp ~/(path of the file in yout computer) [email protected]:/homes/users/user_name/(folder where you want your file to be or the name of the file)

 

Next, log in to the cluster from a terminal, go to the corresponding folder where your files are saved and run the sbatch file:

$ sbatch sbatch_exampe.sh

 

This will generate a slurm file (slurm-[number].out) that will let you check the output of your code using the command:

$ more slurm-[number].out