ConnorDonegan / geostan

Bayesian spatial analysis
https://connordonegan.github.io/geostan
Other
56 stars 5 forks source link

Compatibility with Future RStan #2

Closed andrjohns closed 2 years ago

andrjohns commented 2 years ago

This PR contains some minor changes to make your package compatible with the upcoming RStan 2.26. I've removed the src folder and stanmodels.R file, as these are fully handled by rstantools.

I've also made a small change to the model.stan file, where the rep_vector(mu_x_true[j], n) argument is first assigned to a temporary vector before being passed to the auto_normal_lpdf likelihood. This is due to some transition issues when using the older rstan with the newer StanHeaders, and can be reverted once the newer versions of both are on CRAN.

Feel free to let me know if you had any questions!

ConnorDonegan commented 2 years ago

Hey, Thanks for working on this!

Removal of src and stanmodels.R seems to cause problems though. Can they be left in there? Do I need to adjust my workflow for it to work this way? I guess I don't know how to let rstantools handle this part.

When I try to run any of the models (e.g. devtools::test()) it complains about missing stanmodels

Error in `h(simpleError(msg, call))`: error in evaluating the argument 'object' in selecting a method for function 'sampling': object 'stanmodels' not found
andrjohns commented 2 years ago

Ah of course, I should have clarified. With the src and stanmodels.R removals, these are now generated on package installation/building by rstantools - this is what the configure and configure.win files take care of.

To recreate this locally (i.e., for running tests and similar), you just need to call rstantools::rstan_config() - this will then create the src and stanmodels.R files. Apologies for not including that in the original post!

We're recommending this approach so that any changes to rstan requiring config changes will automatically be managed by rstantools, which will help simplify changes in the future

ConnorDonegan commented 2 years ago

I see, that works. Thanks for your help! I'll delete those files for my other RStan-base package (surveil) too.