[R] Why would something work in R but not Rscript?
Jeff Hansen
dscheffy at gmail.com
Wed Nov 19 17:48:34 CET 2014
I have a script that uses RWeka (and consequently rJava). When I run
it in Rstudio everything works fine. When I run it with `R CMD BATCH`,
everything also works fine. However, when I run it with Rscript, I get
the following error:
Error in FUN(X[[1L]], ...) :
object is not a Java object reference (jobjRef/jarrayRef).
Calls: evaluate_Weka_classifier -> t -> sapply -> lapply -> FUN
Execution halted
The following is a very simple toy script that you can run to produce
the results:
library("RWeka")
result <- c(TRUE,FALSE,TRUE,FALSE,TRUE)
observation <- c(TRUE,FALSE,TRUE,FALSE,TRUE)
df <- data.frame(result,observation)
j48 <- J48(result ~ .,data=df)
evaluate_Weka_classifier(j48)
Save that to a file called help.R and run
R CMD BATCH help.R
Check the output file help.Rout and you should see no errors. Now try
running it from:
Rscript help.R
And you should see the error I've pasted above.
I have consulted (and will continue to consult) the literature, but
the manuals tend to answer how usage differs between the two commands
rather than going into implementation details. I imagine there's a
difference in how environments get loaded and I just need to adjust
something on the Rscript side.
I'm working on a Mac (OSX) running R 3.1.0, but I get the same results
when I run everything from a Centos 6.4 virtual machine (headless)
with R 3.1.1 installed.
Thanks for any help!
More information about the R-help
mailing list