File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -653,7 +653,17 @@ variables <- function() {
653
653
}
654
654
assert_stan_file_exists(self $ stan_file())
655
655
if (is.null(private $ variables_ ) && file.exists(self $ stan_file())) {
656
- private $ variables_ <- model_variables(self $ stan_file(), self $ include_paths(), allow_undefined = private $ using_user_header_ )
656
+ private $ variables_ <- model_variables(
657
+ stan_file = self $ stan_file(),
658
+ include_paths = {
659
+ if (length(self $ exe_file()) > 0 && file.exists(self $ exe_file())) {
660
+ self $ include_paths()
661
+ } else {
662
+ private $ precompile_include_paths_
663
+ }
664
+ },
665
+ allow_undefined = private $ using_user_header_
666
+ )
657
667
}
658
668
private $ variables_
659
669
}
Original file line number Diff line number Diff line change @@ -108,3 +108,36 @@ test_that("$variables() errors on no stan_file", {
108
108
fixed = TRUE
109
109
)
110
110
})
111
+
112
+ test_that(" $variables() works with #includes, both pre and post compilation." , {
113
+
114
+ data_code <- "
115
+ data {
116
+ int N;
117
+ }
118
+ "
119
+ model_code <- "
120
+ #include data.stan
121
+ parameters {
122
+ vector[N] y;
123
+ }
124
+ model {
125
+ y ~ std_normal();
126
+ }
127
+ "
128
+
129
+ model_file <- write_stan_file(code = model_code )
130
+ data_file <- write_stan_file(code = data_code , basename = " data.stan" )
131
+
132
+ mod <- cmdstan_model(
133
+ stan_file = model_file ,
134
+ include_paths = dirname(data_file ),
135
+ compile = FALSE
136
+ )
137
+
138
+ vars_pre <- mod $ variables()
139
+ mod $ compile()
140
+ vars_post <- mod $ variables()
141
+
142
+ expect_equal(vars_pre , vars_post )
143
+ })
You can’t perform that action at this time.
0 commit comments