Exposing Stan user-defined functions using CmdStanR and Rcpp

I have written a tutorial on how to expose user-defined Stan functions to R using CmdStanR and Rcpp. You can read the tutorial here.

I have refactored the expose_cmdstanr_functions() R function that I previously posted on Discourse a few times. The code can be found here. It is also linked and included in the tutorial

Any comments or suggestions are welcome. You can comment here or on the repository’s issue tracker.

7 Likes

Thanks so much. I LOVE THIS!!! So great to test and apply functions directly with cmdstanr (rather than rstan).

One question is about compiling. Right now it looks like the expose command recompiles the Stan code (which takes time). Is there anyway after compiling once to keep the compiled code in the same directory with Stan code and then subsequently just load the compiled code? This would be directly analogous to what we can do with full Stan code. We compile it once and the next time it can just be loaded (and cmdstanr tells us the model executable is up to date).

Thanks for the kind words.

Yes, I think that should be doable. Would you mind posting this request on the issue tracker so I dont forget? Might be able to get to this over the weekend.