Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R phangorn Rscript R CMD批处理不同的结果_R - Fatal编程技术网

R phangorn Rscript R CMD批处理不同的结果

R phangorn Rscript R CMD批处理不同的结果,r,R,尝试使用phangorn包运行R脚本时,我收到一个奇怪的错误。每当我使用以下命令运行脚本时: Rscript mini_示例.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 这可能意味着名称空间出现了一些问题

尝试使用
phangorn
包运行
R
脚本时,我收到一个奇怪的错误。每当我使用以下命令运行脚本时:
Rscript mini_示例.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_示例.R

library(phangorn)
sessionInfo()
data(Laurasiatherian)
dm <- dist.ml(Laurasiatherian)
tree <- NJ(dm)
fitJC <- pml(tree, Laurasiatherian)  
fitJC <- optim.pml(fitJC)
print('==>>Success <<==') 
用于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  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      methods_3.2.1   lattice_0.20-31
[9] quadprog_1.5-5 

如果除了导入
phangorn
之外,还导入了
library(methods)
,则可以使用
Rscript
。这将
方法的sessionInfo()从“通过名称空间加载(且未附加)”更改为“附加的基本包”,这是
Rscript
的sessionInfo()与
R CMD批处理的唯一区别


我不知道为什么两者会有不同。但是,请注意(Rscript的一种替代方法)“
littler
的作者也遇到过您的问题。”

您的解决方案有效。引用自
?Rscript
:Rscript省略了方法,因为它需要大约60%的启动时间。。。这就是我不知道的原因。
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  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      methods_3.2.1   lattice_0.20-31
[9] quadprog_1.5-5