How to specify include path when compiling stan models?


#1

Hi,

I use several different models which all share the same data block format. I would therefore like to put this data block into a separate file “standard_data_block.stan” and then use the #include mechanism mentioned in the manual. So at the top of each model I would place
#include “standard_data_block.stan”

However for this to work I need to specify an include-path. The manual only alludes to some mechanism for doing this but doesn’t specify the exact method. After looking through some of the source code, I think this is done by specifying --include-paths as a STANCFLAG when running make. However I can’t get this working properly, the compiler still complains that it couldn’t find the right include file.

This is the command I’m running, does it look correct? The model is bias_sens.stan, and in the same parent directory I have the data_block file.

peter at pzh in ~/cmdstan-2.17.1
$ make STANCFLAGS="–include-paths=/Users/peter/Desktop/stan2AFC/models" /Users/peter/Desktop/stan2AFC/models/bias_sens

— Translating Stan model to C++ code —
bin/stanc --include-paths=/Users/peter/Desktop/stan2AFC/models /Users/peter/Desktop/stan2AFC/models/bias_sens.stan --o=/Users/peter/Desktop/stan2AFC/models/bias_sens.hpp
Model name=bias_sens_model
Input file=/Users/peter/Desktop/stan2AFC/models/bias_sens.stan
Output file=/Users/peter/Desktop/stan2AFC/models/bias_sens.hpp

could not find include file
make: *** [/Users/peter/Desktop/stan2AFC/models/bias_sens.hpp] Error 255

If it’s not correct, what is the command I should be using to specify an include path for STANC? Thank you!


#2

I think that is more for including C++ headers that define undefined user-defined functions. To insert some Stan code, it should just work but it is very difficult. Make sure that the #include statement is flush left. Then make sure there is no quotes surrounding the filename. Then make sure there are no spaces. Then make sure there is nothing to the right of the filename, not even whitespace or comments.