File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -265,7 +265,11 @@ CmdStanModel <- R6::R6Class(
265
265
invisible (self )
266
266
},
267
267
include_paths = function () {
268
- private $ include_paths_
268
+ if (length(self $ exe_file()) > 0 && file.exists(self $ exe_file())) {
269
+ return (private $ include_paths_ )
270
+ } else {
271
+ return (private $ precompile_include_paths_ )
272
+ }
269
273
},
270
274
code = function () {
271
275
if (length(private $ stan_code_ ) == 0 ) {
@@ -653,7 +657,11 @@ variables <- function() {
653
657
}
654
658
assert_stan_file_exists(self $ stan_file())
655
659
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_ )
660
+ private $ variables_ <- model_variables(
661
+ stan_file = self $ stan_file(),
662
+ include_paths = self $ include_paths(),
663
+ allow_undefined = private $ using_user_header_
664
+ )
657
665
}
658
666
private $ variables_
659
667
}
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