R phangorn Rscript R CMD BATCH的结果不同

时间:2015-09-07 14:39:34

标签: r

尝试使用R程序包运行phangorn脚本时收到奇怪的错误。每当我使用以下命令运行脚本时: Rscript mini_example.R 它失败并显示错误消息:

Error in as.vector(data) : 
no method for coercing this S4 class to a vector
Calls: pml ... as.matrix -> as.matrix.default -> array -> as.vector

这可能表明一些命名空间的麻烦。但是,当运行R CMD BATCH mini_example.R OUT.txt时,一切运行顺利,没有错误。

代码mini_example.R

library(phangorn)
sessionInfo()
data(Laurasiatherian)
dm <- dist.ml(Laurasiatherian)
tree <- NJ(dm)
fitJC <- pml(tree, Laurasiatherian)  
fitJC <- optim.pml(fitJC)
print('==>>Success <<==') 

我比较了sessionInfo()Rscript的{​​{1}}(见下文),唯一的区别是使用R CMD BATCH时没有附加方法但通过命名空间加载。我对这种行为感到有点困惑,所以如果有更多知识的人可能会知道可能导致Rscript麻烦的事情,那就太棒了......

对于R CMD BATCH

Rscript

对于Rscript

R version 3.2.1 (2015-06-18)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.9.5 (Mavericks)

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] phangorn_1.99.14 ape_3.3         

loaded via a namespace (and not attached):
[1] Matrix_1.2-2    nnls_1.4        parallel_3.2.1  igraph_0.7.1   
[5] nlme_3.1-120    grid_3.2.1      lattice_0.20-31 quadprog_1.5-5 

1 个答案:

答案 0 :(得分:2)

除了Rscript之外,如果您导入library(methods),则此问题适用于phangorn。这会将methods的sessionInfo()从“通过命名空间加载(而不是附加)”更改为“附加基本包”,这是Rscript与{{R CMD BATCH的sessionInfo()之间的唯一区别1}}。

我不知道为什么两者会有所不同。但是,this answer评论littler(替代Rscript)“加载方法包”,这表明littler的作者也遇到过您的问题。< / p>