Reputation: 589
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!
Upvotes: 11
Views: 969
Reputation: 368241
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.
Upvotes: 15