High-level help with how to compile a model from within R

Forgive me if this question is too open-ended or broad, but can anyone provide some high-level resources on how compiling models from within R works? I would like to know more about how models are turned into c++ classes.

My situation is that I have some class templates in c++ that I would like to be able to use in R, and I’m not sure how to get started on this project. Which part of Stan achieves this? Perhaps I can use some of those tools!

I think it’s Rcpp based. This is a slick way to interface C++ and R: https://cran.r-project.org/web/packages/Rcpp/index.html . Check out the introduction pdf there. I don’t really know anything else about it, but I think the Rcpp discussion is pretty active on Stackoverflow if you needed something specific.

The RStan package uses the cxxfunction function in the inline package and the sourceCpp function in the Rcpp package.

Don’t those need real c++ code? How does that pseudo-c++ model specification file given by the end-user get translated before this step?

Yes, you need genuine C++ code which is provided by the stanc function in Stan.

1 Like