[R] How to save/load RWeka models into/from a file?

Paulo Cortez pcortez at dsi.uminho.pt
Fri Oct 17 12:32:38 CEST 2008

Achim Zeileis wrote:
> On Thu, 16 Oct 2008, Paulo Cortez wrote:
>> Hi,
>> I want to save a RWeka model into a file, in order to retrive it 
>> latter with a load function.
>> See this example:
>> library(RWeka)
>> NB <- make_Weka_classifier("weka/classifiers/bayes/NaiveBayes")
>> model<-NB(formula,data=data,...) # does not run but you get the idea
>> save(model,file="model.dat") # simple save R command
>> # ...
>> load("model.dat") # load the model from the previously saved file...
>> model # should work but I get instead this error:
>> Error in .jcall(x$classifier, "S", "toString") :
>>  RcallMethod: attempt to call a method of a NULL object.
>> What is wrong and how can I solve this problem?
> The R object is just a reference to the corresponding object on the Java 
> side (in Weka). When you close R, the Java/Weka session is also closed 
> and the model is gone. Thus, when you load the object again in a new 
> session, you only have a reference to a Java object that does not live 
> anymore.
> Z

Thanks, I understand now what is happening.

Yet, I still need to save/load a RWeka model to/from a file.
Thus, how can I do this? Is it impossible in R? Any help?

Paulo Alexandre Ribeiro Cortez  (PhD, MSc)
Lecturer (Prof. Auxiliar) at the Department of Information Systems (DSI)
University of Minho, Campus de AzurÈm, 4800-058 Guimaraes, Portugal
http://www.dsi.uminho.pt/~pcortez +351253510313 Fax:+351253510300

More information about the R-help mailing list