Skip to content

Commit 5b39ed0

Browse files
committed
add stancflags from make/local
1 parent 03d568b commit 5b39ed0

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

R/model.R

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,12 @@ compile <- function(quiet = TRUE,
550550
stanc_built_options <- c(stanc_built_options, paste0("--", option_name, "=", "'", stanc_options[[i]], "'"))
551551
}
552552
}
553-
stancflags_val <- paste0("STANCFLAGS += ", stancflags_val, paste0(" ", stanc_built_options, collapse = " "))
553+
make_local_stancflags <- get_make_variable("STANCFLAGS")
554+
stancflags_val <- paste0(
555+
"STANCFLAGS += ",
556+
stancflags_val,
557+
paste0(c(" ", stanc_built_options, make_local_stancflags), collapse = " ")
558+
)
554559
withr::with_path(
555560
c(
556561
toolchain_PATH_env_var(),
@@ -769,7 +774,12 @@ check_syntax <- function(pedantic = FALSE,
769774
),
770775
run_log <- wsl_compatible_run(
771776
command = stanc_cmd(),
772-
args = c(wsl_safe_path(self$stan_file()), stanc_built_options, stancflags_val),
777+
args = c(
778+
wsl_safe_path(self$stan_file()),
779+
stanc_built_options,
780+
stancflags_val,
781+
get_make_variable("STANCFLAGS")
782+
),
773783
wd = cmdstan_path(),
774784
echo = is_verbose_mode(),
775785
echo_cmd = is_verbose_mode(),
@@ -909,8 +919,12 @@ format <- function(overwrite_file = FALSE,
909919
),
910920
run_log <- wsl_compatible_run(
911921
command = stanc_cmd(),
912-
args = c(wsl_safe_path(self$stan_file()), stanc_built_options,
913-
stancflags_val),
922+
args = c(
923+
wsl_safe_path(self$stan_file()),
924+
stanc_built_options,
925+
stancflags_val,
926+
get_make_variable("STANCFLAGS")
927+
),
914928
wd = cmdstan_path(),
915929
echo = is_verbose_mode(),
916930
echo_cmd = is_verbose_mode(),

R/utils.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,25 @@ as_mcmc.list <- function(x) {
512512
class(mcmc_list) <- 'mcmc.list'
513513
return(mcmc_list)
514514
}
515+
516+
get_make_variable <- function(var_name) {
517+
ret <- wsl_compatible_run(
518+
command = make_cmd(),
519+
args = c(paste0("print-", var_name)),
520+
wd = cmdstan_path(),
521+
echo_cmd = is_verbose_mode(),
522+
echo = is_verbose_mode(),
523+
error_on_status = FALSE
524+
)
525+
if (ret$status == 0) {
526+
stancflags <- trimws(
527+
gsub(
528+
paste0(var_name, " ="), "",
529+
ret$stdout, fixed = TRUE
530+
)
531+
)
532+
} else {
533+
stancflags <- ""
534+
}
535+
return(stancflags)
536+
}

0 commit comments

Comments
 (0)