I'm receiving strange error when trying to run an R
script using the phangorn
package. Whenever I run the script using:
Rscript mini_example.R
It fails with the error message:
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
Which could suggest some Namespace troubles. However when running R CMD BATCH mini_example.R OUT.txt
everything runs smooth, no errors.
Code 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 <<==')
I've compared the sessionInfo()
for both the Rscript
and the R CMD BATCH
(see below) and the only difference is that methods is not attached when using Rscript
but loaded via Namespace. I'm a bit confused about this behavior, so it would be great if someone with more knowledge might have an idea what might cause the Rscript
trouble...
For R CMD BATCH
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
For 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