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.
Open the VI text editor through the terminal and copy the above code. Save this code as an r file (i.e. your_code.r). Next, proceed to create a sbatch file with the same text editor that has the following structure:
#!/bin/bash
#SBATCH --job-name=test
#SBATCH --cpus-per-task=1
#SBATCH --mem-per-cpu=8G
#SBATCH --mail-type=END
#SBATCH [email protected]
# For the next step, choose the module R/X.X.X that you need (module av to see available modules):
module load R/X.X.X
Rscript your_code.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