Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rcpp: Save compiled function as Robj

If I define a function in R, I can save the function object using the save function. Then I can load that function object using the load function and use it directly. However, if I have a rcpp function, and if I try to save the compiled version and load it back to the memory, I can no longer use that function object directly. Is this even possible? The reason I ask is because it takes a while to compile the function, and if there is a way to avoid that cost every time I launch an R environment, that will be great. Thanks!

like image 453
Chris Avatar asked Mar 04 '13 01:03

Chris


1 Answers

No, in general you cannot serialize (and hence save) a function compiled with cxxfunction() or sourceCpp(). You need to freshly compile it, unless you place it in a package. Which is why packages are the way to go to really install your compiled code beyond quick experimentation.

like image 152
Dirk Eddelbuettel Avatar answered Oct 23 '22 03:10

Dirk Eddelbuettel