You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改sbatch执行job.sh生成的test.Rout文件存储位置

How to Change the Storage Location of test.Rout in Your SLURM Job

Got it, let's sort out how to redirect that test.Rout file to a folder of your choice. Looking at your job.sh script, here's what's happening right now and how to adjust it:

First, the reason test.Rout lands in the same directory as job.sh is because when you run R CMD BATCH test.R (or your current command with a small typo—we'll fix that), R defaults to saving the .Rout output in the job's starting working directory unless you tell it otherwise.

Here are two simple, reliable ways to change this:

1. Explicitly Define the Output Path in R CMD BATCH

The R CMD BATCH command lets you specify exactly where to save the .Rout file by adding your target path as the second argument.

First, fix the typo in your current script:
Your existing line R CMD BATCH test.R test.R would overwrite your input test.R file—definitely not what you want! Replace that with a path to your desired output location.

Example: Save to a dedicated output folder

Let's say you want to store test.Rout in a folder called r_output (we'll add a line to create this folder if it doesn't exist):

#!/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

# Create the output directory if it doesn't exist
mkdir -p r_output

module load R
# Directly specify where to save test.Rout
R CMD BATCH test.R r_output/test.Rout

This will drop test.Rout straight into the r_output folder. You can also use an absolute path (like /home/yourusername/projects/results/test.Rout) if you want it saved to a fixed, specific location.

2. Switch the Job's Working Directory

If you prefer to keep using R's default .Rout naming but want all job-related files (including this one) to go to a different directory, use the cd command to change the job's working directory early in your script.

Example:

#!/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

# Create target directory and switch to it
mkdir -p /path/to/your/target/folder
cd /path/to/your/target/folder

module load R
# Make sure to use the full path to your test.R script here
R CMD BATCH /path/to/your/original/test.R

Now R will save test.Rout in the directory you switched to with cd.

Quick Side Note

That print(2+2) line in your current job.sh won't run as intended—it's an R command but is being executed as bash. If you want that code to run, move it inside your test.R file instead.


内容的提问来源于stack exchange,提问作者problème0123

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:26:47