@@ -109,6 +109,64 @@ test_that("compilation works with include_paths", {
109109 )
110110})
111111
112+ test_that(" precompiled models retain include paths" , {
113+ model_dir <- withr :: local_tempdir()
114+ write_stan_file(
115+ "
116+ functions {
117+ real silly_logit(real x) {
118+ return logit(x);
119+ }
120+ }
121+ " ,
122+ dir = file.path(model_dir , " utils" ),
123+ basename = " silly.stan"
124+ )
125+ stan_file <- write_stan_file(
126+ "
127+ #include utils/silly.stan
128+ data {
129+ int<lower=0> N;
130+ array[N] int<lower=0, upper=1> y;
131+ }
132+ parameters {
133+ real<lower=0, upper=1> theta;
134+ }
135+ model {
136+ theta ~ beta(1, 1);
137+ y ~ bernoulli(theta);
138+ }
139+ generated quantities {
140+ real theta_lin = silly_logit(theta);
141+ }
142+ " ,
143+ dir = model_dir ,
144+ basename = " bernoulli.stan"
145+ )
146+ compiled_model <- cmdstan_model(
147+ stan_file ,
148+ include_paths = model_dir ,
149+ quiet = TRUE
150+ )
151+
152+ model_with_explicit_path <- cmdstan_model(
153+ stan_file ,
154+ exe_file = compiled_model $ exe_file(),
155+ compile = FALSE ,
156+ include_paths = model_dir
157+ )
158+ expect_equal(model_with_explicit_path $ include_paths(), model_dir )
159+ expect_no_error(model_with_explicit_path $ variables())
160+
161+ model_with_automatic_path <- cmdstan_model(
162+ stan_file ,
163+ exe_file = compiled_model $ exe_file(),
164+ compile = FALSE
165+ )
166+ expect_equal(model_with_automatic_path $ include_paths(), dirname(stan_file ))
167+ expect_no_error(model_with_automatic_path $ variables())
168+ })
169+
112170test_that(" name in STANCFLAGS is set correctly" , {
113171 local_reproducible_output()
114172 out <- utils :: capture.output(mod $ compile(quiet = FALSE , force_recompile = TRUE ))
0 commit comments