2

When I make the command sbatch job.sh and everything runs smoothly, a file test.Rout is generated at the location of my job.sh, I would like to know how to change the location of this .Rout file.

job.sh

#!/bin/bash
#SBATCH --job-name="test
#SBATCH --nodes=1                # number of nodes
#SBATCH --ntasks-per-node=10      # number of cores
#SBATCH --time=01:00:00          # walltime
#SBATCH --output=error/job.out
#SBATCH --error=error/error.err

module load R

R CMD BATCH test.R

test.R

print(2+2)

test.Rout

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

> print(2+2)
[1] 4
>
> proc.time()
   user  system elapsed
  0.107   0.039   0.154
problème0123
  • 841
  • 2
  • 9
  • 23

1 Answers1

4

Note that the test.Rout file is not generated by the job.sh, it is generated by the R CMD BATCH command. From the documentation, it suffices to add the name of the output file as last argument.

R CMD BATCH test.R /path/to/target/dir/test.Rout

Note that, according to this, you might want to consider Rscript. In that case, you can either redirect the Rscript output with >

Rscript test.R > /path/to/target/dir/test.Rout

in which case the file is written by Bash, or or use the --output option of sbatch in which case the output file is written by Slurm:

#SBATCH --output=/path/to/target/dir/test.Rout
Rscript test.R

but it will contain the full output of the job, not only the R part.

damienfrancois
  • 52,978
  • 9
  • 96
  • 110
  • Is there a way to add a special character so that the name of the R script is used? Something similar to ```#SBATCH --output "out/slurm-%j.out"```, where the %j adds the number of the job to the file. – desval Jul 29 '21 at 10:08