When using Rscript, the 'methods' package is not loaded/attached by
default, which it is when you use R.  See ?Rscript for details.  For
any scripts intended for batch usage, the safest is to only assume
that 'base' is attached, but nothing else.

/Henrik

On Wed, Nov 19, 2014 at 10:03 AM, Ben Tupper <[email protected]> wrote:
> Hi,
>
> On Nov 19, 2014, at 11:48 AM, Jeff Hansen <[email protected]> wrote:
>
>> 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
>>
>
> You might try using the the --vanilla option for each.  At least then you can 
> rule out that something is being restored in the session of one but not the 
> other.
>
> R --vanilla CMD BATCH help.R
> Rscript --vanilla help.R
>
> Cheers,
> Ben
>
>
>> 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!
>>
>> ______________________________________________
>> [email protected] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to