【发布时间】:2016-02-20 21:15:26
【问题描述】:
我的计算机上有一个要从命令行运行的文件。该文件将在其中发生一些事情+一个函数。
例如,我有一个全局变量 start_value=10,然后我在 Rscript 中调用了一个函数。我想在传递参数的同时运行这个脚本
我试图在网上找到如何做到这一点,但我没有运气。
我收到此错误:
Error in help_function(x, y) : object 'x' not found
这样运行时:
Rscript helpme.R 100 10
-
##?? saw this someplaces when searching, but couldn't get it to work
args = commandArgs(trailingOnly=TRUE)
starting_value=10
help_function = function(x,y){
division =x/y
answer=starting_value + division
return(answer)
}
help_function(x,y)
【问题讨论】:
-
您需要从
args中挑选出参数,并在必要时对其进行处理,as for example here。 -
很明显,如果您从未在脚本中定义它,R 将无法找到
x...
标签: r function terminal rscript