Rscript无法找到功能

时间:2013-10-19 16:50:39

标签: r rscript

我需要使用Rscript通过bash shell运行多个脚本,我使用的一些函数需要函数isGeneric。但是,在这种情况下,流程就像那样(例如):

Error in .getLogLik() : could not 
find function "isGeneric"
Calls: main -> dredge -> .getLik -> .getLogLik
Execution halted

这可以转载如下

# in the bash shell
echo "isGeneric('apply')" > /tmp/test.R
Rscript /tmp/test.R

结果:

Error: could not find function "isGeneric"
Execution halted

但是,如果我们打开R会话并键入以下内容,则可以:

# in the R shell
isGeneric('apply')
[1] FALSE

您是否知道问题的来源以及如何解决问题?

1 个答案:

答案 0 :(得分:23)

根据help(Rscript)Rscript默认情况下不加载方法包,因为它很耗时。因此,您需要在命令行中指定它:

Rscript --default-packages=methods file.R

library(methods)位于您正在呼叫的文件的顶部。