【问题标题】:Rscript could not find functionRscript 找不到函数
【发布时间】:2013-10-28 09:49:48
【问题描述】:

我需要使用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

您知道问题出在哪里以及如何解决吗?

【问题讨论】:

    标签: r rscript


    【解决方案1】:

    根据help(Rscript)Rscript 默认不加载方法包,因为它很耗时。所以你要么需要在命令行上指定它:

    Rscript --default-packages=methods file.R
    

    library(methods) 在您正在调用的文件的顶部。

    【讨论】:

    • 感谢 Joshua,它现在可以正常工作了。抱歉,我没有看到 isGenericmethods 包之间的链接。
    • @LudoDuvaux:不用担心。除非您以前遇到过此问题,否则这不是一个明显的链接。
    • 我刚刚遇到了Error: could not find function "is"。那里的联系就更不明显了!
    • 命令(根据 help(Rscript))应该是:Rscript --default-packages=methods,datasets,utils,grDevices,graphics,stats,以便拥有与 R 相同的默认包——如果你只包含方法,那么还有一堆其他的东西失踪
    猜你喜欢
    • 2020-04-22
    • 2019-11-20
    • 1970-01-01
    • 2013-06-29
    • 2022-10-05
    • 2019-06-08
    • 2019-09-09
    相关资源
    最近更新 更多