Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precompiling your Stan programs #3

Closed
bgoodri opened this issue Jul 21, 2016 · 2 comments
Closed

Precompiling your Stan programs #3

bgoodri opened this issue Jul 21, 2016 · 2 comments

Comments

@bgoodri
Copy link
Contributor

bgoodri commented Jul 21, 2016

It is good to see another package on CRAN making use of Stan! But for packages like bmlm that offer a fixed set of Stan models, it is preferable to compile them when the package is built for several reasons:

  1. The vast majority of users --- who are installing binary packages from CRAN for Windows or Mac --- would not need to first install a C++ toolchain in order to use bmlm. Only people who install packages from source would need the C++ toolchain and they probably already have one.
  2. Users would not have to wait 30 -- 60 seconds for the models to start running.
  3. It is somewhat more robust to updates to StanHeaders on CRAN.

The easiest way to do this is to call rstan::rstan.package.skeleton("skeleton") when the working directory is /tmp or something and copy the contents of /tmp/skeleton into your local clone of bmlm. This is how the rstanarm, beanz, and eggCounts R packages work. Ultimately, there will be a list called stanmodels in the bmlm NAMESPACE that you can extract a precompiled stanmodel from to pass to rstan::sampling.

Also, your two .stan files are almost identical except for a couple of lines, so they are good candidates to utilize the #include ... mechanism of rstan::stanc_builder, which is automatic for packages created by rstan::rstan.package.skeleton. You can put .stan files into inst/chunks that have all the common pieces and then put #include "piece.stan" in the appropriate place in your Stan programs and it will paste inst/chunks/piece.stan there. This way, there are fewer mistakes when you change something in one place and forget to change it in the other place(s). See https://github.com/stan-dev/rstanarm/blob/master/exec/polr.stan for one example of how to do this.

@mvuorre
Copy link
Owner

mvuorre commented Jul 21, 2016

This is great, thanks so much for bringing these issues to my attention. I'll include these features in the next update.

@mvuorre
Copy link
Owner

mvuorre commented Jul 22, 2016

These features are included in v1.1.0. Use

devtools::install_github("mvuorre/bmlm", args = "--preclean")

to install v1.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants