更改由 sbatch job.sh 生成的 .file 的位置

change the location of the .file generate by sbatch job.sh

当我发出命令 sbatch job.sh 并且一切运行顺利时,在我的 job.sh 位置生成了一个文件 test.Rout , 我想知道如何更改此 .Rout 文件的位置。

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

注意test.Rout文件不是job.sh生成的,它是由R CMD BATCH命令生成的。从 documentation 开始,添加输出文件的名称作为最后一个参数就足够了。

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

请注意,根据 this,您可能需要考虑 Rscript。在这种情况下,您可以使用 >

重定向 Rscript 输出
Rscript test.R > /path/to/target/dir/test.Rout

在这种情况下,文件由 Bash 写入,或者使用 sbatch 的 --output 选项,在这种情况下,输出文件由 Slurm 写入:

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

但它将包含作业的完整输出,而不仅仅是 R 部分。