bash 通过 qsub 运行 R 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19416972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running R script through qsub
提问by user2763361
I am trying to run an R
script called test.r
through qsub
. My R
script is as follows:
我正在尝试运行一个R
名为test.r
through的脚本qsub
。我的R
脚本如下:
#!/usr/bin/Rscript
x <- 1
write.csv(x,"test.csv")
If in Ubuntu terminal I type R CMD BATCH test.r
, then the script behaves as planned; test.csv
gets exported in the same directory.
如果在 Ubuntu 终端中输入R CMD BATCH test.r
,则脚本按计划运行;test.csv
导出到同一个目录。
However if I create a bash
script called testbash.sh
and run it through the command qsub testbash.sh
; it will run without errors but the output won't be there.
但是,如果我创建一个bash
名为的脚本testbash.sh
并通过命令运行它qsub testbash.sh
;它将运行而不会出错,但不会有输出。
#!/usr/bin/bash
R CMD BATCH test.r
How to fix this?
如何解决这个问题?
回答by Ricardo Oliveros-Ramos
Try modifying your R script to:
尝试将 R 脚本修改为:
#!/usr/bin/Rscript
x <- 1
print(getwd())
write.csv(x,"test.csv")
When you run a script via qsub
, the script is normally running in another server, and by default as in your home directory. You need to change to the original directory in your script, there is a variable PBS_O_WORKDIR
for that:
当您通过 运行脚本时qsub
,该脚本通常在另一台服务器上运行,默认情况下在您的主目录中。您需要更改到脚本中的原始目录,有一个变量PBS_O_WORKDIR
:
#!/usr/bin/bash
#PBS -N qsub_R_test
echo We are in the $PWD directory
cd $PBS_O_WORKDIR
echo We are now in $PBS_O_WORKDIR, running an R script.
R --vanilla < test.r > test.log 2> test.log
I normally cannot use R CMD BATCH
, but redirection to R -vanilla
works. You can also specify options for the PBS in the script, starting with #PBS
, like the job name in this case (qsub_R_test
).
我通常不能使用R CMD BATCH
,但重定向到R -vanilla
工作。您还可以在脚本中为 PBS 指定选项,以 开头#PBS
,例如本例中的作业名称 ( qsub_R_test
)。
You can get a more detailed list of qsub parameters here: http://www.csc.fi/english/pages/louhi_guide/batch_jobs/commands/qsub
您可以在此处获得更详细的 qsub 参数列表:http: //www.csc.fi/english/pages/louhi_guide/batch_jobs/commands/qsub
And an example of a PBS script here: http://bose.utmb.edu/Compu_Center/Cluster_users/PBS%20HOWTO/PBS_HOW_TO.html
以及这里的 PBS 脚本示例:http: //bose.utmb.edu/Compu_Center/Cluster_users/PBS%20HOWTO/PBS_HOW_TO.html
回答by Dirk Eddelbuettel
You may be doing it wrong. If you have a shebang line like
你可能做错了。如果你有像这样的shebang线
#!/usr/bin/Rscript
then "simply" do chmod 0755 test.r
on the file, and run it:
然后“简单地”chmod 0755 test.r
对文件执行操作,然后运行它:
./test.r
That should work, and you can then have that invocation in your qsub-called script.
这应该可行,然后您可以在 qsub 调用的脚本中进行该调用。