Exposed Stan functions for generated quantities in an R package

Thanks for the thorough description, this is really similar to what I think of as best practices and I can see the benefit of wanting to push computations out of R code.

Until we have the generated quantities stuff plumbed through, I suggest writing Stan functions s.t. they take a vector[] theta to represent the parameters and loop over the iterations in theta to do whatever transformations you need. You can use the C++ generated by the current expose_stan_functions. You can also use the R/C++ wrapper that’s generated by expose_stan_functions as well.

A few tricks: 1) Use the 2.18 version of rstan (currently only available as the develop branch on github. The current version still does a bunch of transformations in R code that sometimes cause problems so there’s less to understand with the new version; 2) call expose_stan_functions with the cacheDir argument set so that you can find all the generated code to borrow, it should have all the tags s.t. Rcpp can compile it already; and 3) if you want to make your life easier with the package, rely on expose_stan_functions directly in your code, don’t try to compile it yourself. Now almost all the generated code is generated by either Rcpp or stan-dev/stan code so there are more people interested in making sure it compiles.