Persistent cmdstanr compiled model objects

Hi @jonah et al -

I am wondering whether or not it is possible to store cmdstanr compiled model objects in a persistent manner. Currently it looks like the R6 object contains file paths to executables, however, these seem to be stored in tmp folders, and so that would likely not be persistent.

Is there any straightforward way of saving a compiled model object? The use case here is for using cmdstanr for a separate R package with a model that takes a while to compile, and so it would be preferable to compile once and save it.

Thanks much for any info -


1 Like


the executable is placed in the same folder as the .stan file by default.

You can change its location though. See “Executable location” in

Is that what you are looking for?

1 Like

I think so. As long as that executable stays in the same place, I should be able to save the R6 object and reload it in a separate session, right?

1 Like

I would think so, but will give it a try tomorrow. This should definitely be supported.

1 Like

Ok I think I’ve solved my own problem. cmstanr has a compile check for the executable. So essentially it stores the executable in a persistent fashion so long as the directory is permanent. There’s no need to save the R6 model object as there is no computational overhead to declare it again if compilation of the Stan code isn’t necessary.


Great, glad that’s working for you!

Yes, it seems to be working out pretty well. The fact that cmdstanr checks for the executable on its own makes it really easy to integrate into an R package without needing to worry about bundling C libraries.