{instantiate}: pre-compiled CmdStan models in R packages

The rstantools package has served the community beautifully, allowing us to pre-compile Stan models in R packages much like rstanarm. Aside from the obvious efficiency gains, especially in simulation studies, pre-compiling saves us the trouble of diagnosing compiler errors near runtime. However, the version of Stan in CmdStan is far more advanced, and many of us R package developers are keen to work it into our packages in a seamless way.

To meet the need, I created a package called instantiate. The instantiate package configures other packages to pre-compile their models at installation time, then offers up cmdstanr’s excellent interface without any further compilation. It also offers alternative ways to install and connect to CmdStan which may be more amenable to centralized R installations at large highly-regulated companies. The documentation website is at Pre-Compiled CmdStan Models in R Packages • instantiate. It is a brand new package, and I still have a lot to learn about Stan, but I hope this pattern is useful.

11 Likes

Wow this looks great! Looking forward to trying it out.

1 Like

This is very nice! I tried to put together something similar in Python a while back: New way of packaging Stan models in Python.

The prophet package from Facebook uses it (roughly, I made some changes after helping the Prophet developers) Python interface, but the R one is still depends on RStan as far as I know, it would be interesting to see both have a CmdStan-based release pipeline

2 Likes

Many thanks. I’ve been switching over to cmdstanr because of the way RStan destabilizes R, so your package is a welcome development.

2 Likes