Saving exposed function

[edit: escaped code]

Hi,

I am trying to save exposed function with the following code:

fun <- cmdstan_model(paste0("fun.stan"), quiet = FALSE)
fun$expose_functions()
fsave <- fun$functions$foo
saveRDS(fsave, file = "foo.RDS")
rm(fsave)

However

readRDS("foo.RDS")

produces

.Call(<pointer: (nil) >,...)

What I am doing wrong?

Many thanks for any insight.

I’m not sure you’re going to be able to save something like that because it links into our underlying C++ and I don’t think R has a way to serialize that.

@bgoodri or @Jonah should have a definitive answer.

Why not just reconstruct the function rather than trying to read it out of a saved binary?