I made functions that I use in many of my models (argmax, argmin, etc). Do I have to paste these into all of my model files or is there some way to “include” a file of user defined functions?
Yea see helpful_stan_functions/skew_generalized_t_example.stan at main · spinkney/helpful_stan_functions · GitHub and the corresponding R code
I do need to add that you’ll have to rename the file as a .stan file so the stanc3 parser accepts it. The next version of stanc3 can parse .stanfunctions files.
I’ve gone all in the next version as the stanc parser will auto format Stan code, including files that are stand alone Stan functions.
Whoa. Thank you very much. !!!
I’m wondering, could I have found this in the docs? If so, could you point me to it? I’m trying to get better at navigating the docs.
I don’t know. Possibly @rok_cesnovar or @WardBrian knows. If it’s missing or hard to find we should update the docs.
I don’t think it’s hard to find. I found it here: 2 Includes | Stan Reference Manual
I should look harder next time.
Ah but this doesn’t have everything. You don’t have to include the entire function block in the included file. So this does need updating. Though it will probably wait until .stanfunctions is in to make this more clear.
Oh yeah, that’s actually really cool you don’t have to include the entire function block. Because then you can mix and match “common” and “model-specific” functions.
It’s currently true that you can include just arbitrary segments, but I don’t think that’s super clear in the doc