diff --git a/R/model.R b/R/model.R index f55c23be..7f298b11 100644 --- a/R/model.R +++ b/R/model.R @@ -634,6 +634,8 @@ compile <- function(quiet = TRUE, } stancflags_standalone <- c("--standalone-functions", stancflags_val, stancflags_combined) self$functions$hpp_code <- get_standalone_hpp(temp_stan_file, stancflags_standalone) + private$model_methods_env_ <- new.env() + private$model_methods_env_$hpp_code_ <- get_standalone_hpp(temp_stan_file, c(stancflags_val, stancflags_combined)) self$functions$external <- !is.null(user_header) self$functions$existing_exe <- FALSE @@ -720,10 +722,8 @@ compile <- function(quiet = TRUE, private$precompile_cpp_options_ <- NULL private$precompile_stanc_options_ <- NULL private$precompile_include_paths_ <- NULL - private$model_methods_env_ <- new.env() if(!dry_run) { - suppressWarnings(private$model_methods_env_$hpp_code_ <- readLines(private$hpp_file_, warn = FALSE)) if (compile_model_methods) { expose_model_methods(env = private$model_methods_env_, verbose = !quiet, diff --git a/R/utils.R b/R/utils.R index a2f1fc43..00fe3fae 100644 --- a/R/utils.R +++ b/R/utils.R @@ -800,6 +800,10 @@ create_skeleton <- function(param_metadata, model_variables, } get_standalone_hpp <- function(stan_file, stancflags) { + name <- strip_ext(basename(stan_file)) + path <- dirname(stan_file) + hpp_path <- file.path(path, paste0(name, ".hpp")) + status <- withr::with_path( c( toolchain_PATH_env_var(), @@ -807,16 +811,12 @@ get_standalone_hpp <- function(stan_file, stancflags) { ), wsl_compatible_run( command = stanc_cmd(), - args = c(stan_file, - stancflags), + args = c(paste0("--o=", hpp_path), stancflags, stan_file), wd = cmdstan_path(), error_on_status = FALSE ) ) if (status$status == 0) { - name <- strip_ext(basename(stan_file)) - path <- dirname(stan_file) - hpp_path <- file.path(path, paste0(name, ".hpp")) hpp <- suppressWarnings(readLines(hpp_path, warn = FALSE)) unlink(hpp_path) hpp