以批处理形式提交R脚本到网格

问题描述:

我想向网格提交R作业。我在MGSA_rand.r 保存的主要研发代码在callmgsa.r我写以批处理形式提交R脚本到网格

print('here') 
source('/home/users/pegah/MGSA_rand.r') 
mgsalooprand($SGE_TASK_ID,382) 

的文件,我使用的文件Rscript.sh调用工作(与-t参数我送corrseponding到$SGE_TASK_ID)

R CMD BATCH --no-save callmgsa.r 

我提交作业是这样的:

qsub -t 1 -cwd -b y -l vf=1000m /home/users/pegah/Rscript.sh 

我既没有错误也没有输出。这个工作就像我提交时一样终止,没有任何输出。你可以帮我吗?
谢谢,Pegah

+0

你试过RSCRIPT的家当?这是创建脚本的常用方式:http://stackoverflow.com/questions/750786/whats-the-best-way-to-use-r-scripts-on-the-command-line – flodel 2012-02-19 12:12:40

+0

如果$ SGE_TASK_ID是一个环境变量,你需要使用'Sys.getenv(“SGE_TASK_ID”)'在你的R脚本中访问它。 – flodel 2012-02-19 12:38:57

变量$SGE_TASK_ID是一个shelscript变量。用相同的语法在R中调用它是行不通的。你可以做的是用Rscript代替。从shell脚本调用:

Rscript callmgsa.r $SGE_TASK_ID 

在R脚本,您可以赶上的命令行参数,如:

args <- commandArgs(trailingOnly = TRUE) 
print('here') 
source('/home/users/pegah/MGSA_rand.r') 
mgsalooprand(args[1],382) 

这应该工作...

+0

感谢您的回答。但是我应该在哪里调用R本身?我已经在Rscript.sh中调用它。 – Pegah 2012-02-19 18:32:42

+0

您可以通过shell脚本使用Rscript调用R。 – 2012-02-19 22:14:44

+0

......或者在你的callmgsa.r的顶部放置一个shebang,如'#!/ path_to_R_install/bin/Rscript',并使该文件成为可执行的'chmod + x callmgsa.r'。 – flodel 2012-02-19 22:33:47