Skip to content

Commit b78b843

Browse files
authored
Merge pull request #775 from adrian-lison/master
Fix model$format and model$check_syntax for compiled models with include-paths
2 parents 62bd6d0 + eee6b96 commit b78b843

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

R/model.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,8 @@ check_syntax <- function(pedantic = FALSE,
784784
if (length(stanc_options) == 0 && !is.null(private$precompile_stanc_options_)) {
785785
stanc_options <- private$precompile_stanc_options_
786786
}
787-
if (is.null(include_paths) && !is.null(private$precompile_include_paths_)) {
788-
include_paths <- private$precompile_include_paths_
787+
if (is.null(include_paths) && !is.null(self$include_paths())) {
788+
include_paths <- self$include_paths()
789789
}
790790

791791
temp_hpp_file <- tempfile(pattern = "model-", fileext = ".hpp")
@@ -922,7 +922,7 @@ format <- function(overwrite_file = FALSE,
922922
lower = 1, len = 1, null.ok = TRUE
923923
)
924924
stanc_options <- private$precompile_stanc_options_
925-
stancflags_val <- include_paths_stanc3_args(private$precompile_include_paths_)
925+
stancflags_val <- include_paths_stanc3_args(self$include_paths())
926926
stanc_options["auto-format"] <- TRUE
927927
if (!is.null(max_line_length)) {
928928
stanc_options["max-line-length"] <- max_line_length

tests/testthat/test-model-compile.R

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,15 @@ test_that("check_syntax() works with include_paths", {
406406

407407
})
408408

409+
test_that("check_syntax() works with include_paths on compiled model", {
410+
stan_program_w_include <- testing_stan_file("bernoulli_include")
411+
412+
mod_w_include <- cmdstan_model(stan_file = stan_program_w_include, compile=TRUE,
413+
include_paths = test_path("resources", "stan"))
414+
expect_true(mod_w_include$check_syntax())
415+
416+
})
417+
409418
test_that("check_syntax() works with pedantic=TRUE", {
410419
model_code <- "
411420
transformed data {
@@ -741,6 +750,28 @@ test_that("format() works with include_paths", {
741750
)
742751
})
743752

753+
test_that("format() works with include_paths on compiled model", {
754+
stan_program_w_include <- testing_stan_file("bernoulli_include")
755+
756+
mod_w_include <- cmdstan_model(stan_file = stan_program_w_include, compile=TRUE,
757+
include_paths = test_path("resources", "stan"))
758+
expect_output(
759+
mod_w_include$format(),
760+
"#include ",
761+
fixed = TRUE
762+
)
763+
expect_output(
764+
mod_w_include$format(canonicalize = list('deprecations', 'parentheses', 'braces')),
765+
"#include ",
766+
fixed = TRUE
767+
)
768+
expect_output(
769+
mod_w_include$format(canonicalize = list('includes')),
770+
"real divide_real_by_two",
771+
fixed = TRUE
772+
)
773+
})
774+
744775
test_that("overwrite_file works with format()", {
745776
code <- "
746777
parameters {

0 commit comments

Comments
 (0)