Description
Describe the bug
The new format
method is really nice! However, I noticed that it fails to account for include paths when applied to CmdStanModel objects that were already compiled. The same applies to the check_syntax
method (if include-paths
is not explicitly supplied).
To Reproduce
Just take the corresponding testthat test, which originally only tests an uncompiled model and run it with a compiled model:
stan_program_w_include <- testing_stan_file("bernoulli_include")
mod_w_include <- cmdstan_model(stan_file = stan_program_w_include, compile=TRUE,
include_paths = test_path("resources", "stan"))
expect_output(
mod_w_include$format(),
"#include ",
fixed = TRUE
)
expect_output(
mod_w_include$format(canonicalize = list('deprecations', 'parentheses', 'braces')),
"#include ",
fixed = TRUE
)
expect_output(
mod_w_include$format(canonicalize = list('includes')),
"real divide_real_by_two",
fixed = TRUE
)
})
When running mod_w_include$format()
, I get the following error (with verbose option):
Running bin/stanc PATH_TO_MODEL/bernoulli_include.stan --auto-format
Syntax error in 'PATH_TO_MODEL/bernoulli_include.stan', line 2, column 0, include error:
-------------------------------------------------
1: functions {
2: #include divide_real_by_two.stan
^
3: }
4: data {
-------------------------------------------------
Could not find include file divide_real_by_two.stan in specified include paths.
Error: Syntax error found! See the message above for more information.
Expected behavior
As can be seen above, stanc is run without the '--include-paths' argument. Weirdly, this argument is only missing when the model is precompiled, which is why the original test with an uncompiled model works perfectly fine. I get the same behavior with check_syntax
. However, in contrast to format
, check_syntax
has the possibility to supply include_paths
as an additional argument, and then it works.
CmdStanR version number
0.5.0