richarddmorey / BayesFactor

BayesFactor R package for Bayesian data analysis with common statistical models.
https://richarddmorey.github.io/BayesFactor/
132 stars 49 forks source link

Error when using Rscript #4

Closed richarddmorey closed 10 years ago

richarddmorey commented 10 years ago

The following script causes an error:

#!/usr/bin/Rscript
library("BayesFactor")
data(puzzles)
md = anovaBF(RT ~ shape + color + shape:color + ID, whichRandom = "ID", data = puzzles)
print(md)
## Error in is.data.frame(data) :
##   argument "data" is missing, with no default
## Calls: anovaBF ... myapply -> lapply -> FUN -> reFactorData -> is.data.frame
## Execution halted

Rscript should work without problem; I'm not sure what the error is here.

version yields:

platform       x86_64-apple-darwin10.8.0
arch           x86_64
os             darwin10.8.0
system         x86_64, darwin10.8.0
status
major          3
minor          0.2
year           2013
month          09
day            25
svn rev        63987
language       R
version.string R version 3.0.2 (2013-09-25)
nickname       Frisbee Sailing

BFInfo() yields:

0.9.7
richarddmorey commented 10 years ago

This works:

#!/usr/bin/Rscript
require(methods)
require(BayesFactor)
options(BFprogress=FALSE)
data(puzzles)
md = anovaBF(RT ~ shape + color + shape:color + ID, whichRandom = "ID", data = puzzles)
print(md)

It seems the methods package is needed, and also progress bars must be turned off. From the help on Rscript: "The default for Rscript omits methods as it takes about 60% of the startup time."

lindemann09 commented 10 years ago

Yes this works. Thanks a lot!

Oliver

lindemann09 commented 10 years ago

This is even more elegant and should be maybe done by default:

options(BFprogress=interactive())
richarddmorey commented 10 years ago

Well, the only complication is if the user has already set a BFprogress value, we don't want to overwrite it. But I was planning on adding something like that, yes.

richarddmorey commented 10 years ago

Looks like the bad behavior is caused by a bug in the pbapply package. I've reported it to the author.

richarddmorey commented 10 years ago

Just merged code that fixes this.