Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ CmdStanModel <- R6::R6Class(
checkmate::assert_flag(compile)
private$stan_file_ <- absolute_path(stan_file)
private$stan_code_ <- readLines(stan_file)
private$model_name_ <- sub(" ", "_", strip_ext(basename(private$stan_file_)))
private$model_name_ <- gsub(" ", "_", strip_ext(basename(private$stan_file_)))
private$precompile_cpp_options_ <- args$cpp_options %||% list()
private$precompile_stanc_options_ <- assert_valid_stanc_options(args$stanc_options) %||% list()
if (!is.null(args$user_header) || !is.null(args$cpp_options[["USER_HEADER"]]) ||
Expand All @@ -268,7 +268,7 @@ CmdStanModel <- R6::R6Class(
private$exe_file_ <- repair_path(absolute_path(exe_file))
if (is.null(stan_file)) {
assert_file_exists(private$exe_file_, access = "r", extension = ext)
private$model_name_ <- sub(" ", "_", strip_ext(basename(private$exe_file_)))
private$model_name_ <- gsub(" ", "_", strip_ext(basename(private$exe_file_)))
}
}
if (!is.null(stan_file) && compile) {
Expand Down Expand Up @@ -623,7 +623,9 @@ compile <- function(quiet = TRUE,
stanc_built_options <- c(stanc_built_options, paste0("--", option_name))
} else if (is.null(option_name) || !nzchar(option_name)) {
stanc_built_options <- c(stanc_built_options, paste0("--", stanc_options[[i]]))
} else {
} else if (option_name == "name") { # Quoting model name mangles generated namespace
stanc_built_options <- c(stanc_built_options, paste0("--", option_name, "=", stanc_options[[i]]))
} else {
stanc_built_options <- c(stanc_built_options, paste0("--", option_name, "=", "'", stanc_options[[i]], "'"))
}
}
Expand All @@ -645,7 +647,7 @@ compile <- function(quiet = TRUE,
if (!dry_run) {

if (compile_standalone) {
expose_stan_functions(self$functions, !quiet)
expose_stan_functions(self$functions, verbose = !quiet)
}

withr::with_envvar(
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-model-compile.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ test_that("name in STANCFLAGS is set correctly", {
local_reproducible_output()
out <- utils::capture.output(mod$compile(quiet = FALSE, force_recompile = TRUE))
if(os_is_windows() && !os_is_wsl()) {
out_no_name <- "bin/stanc.exe --name='bernoulli_model' --o"
out_name <- "bin/stanc.exe --name='bernoulli2_model' --o"
out_no_name <- "bin/stanc.exe --name=bernoulli_model --o"
out_name <- "bin/stanc.exe --name=bernoulli2_model --o"
} else {
out_no_name <- "bin/stanc --name='bernoulli_model' --o"
out_name <- "bin/stanc --name='bernoulli2_model' --o"
out_no_name <- "bin/stanc --name=bernoulli_model --o"
out_name <- "bin/stanc --name=bernoulli2_model --o"
}
expect_output(print(out), out_no_name)

Expand Down Expand Up @@ -848,9 +848,9 @@ test_that("STANCFLAGS from get_cmdstan_flags() are included in compile output",
)
out <- utils::capture.output(mod$compile(quiet = FALSE, force_recompile = TRUE))
if(os_is_windows() && !os_is_wsl()) {
out_w_flags <- "bin/stanc.exe --name='bernoulli_model'[[:space:]]+--O1[[:space:]]+--warn-pedantic[[:space:]]+--o"
out_w_flags <- "bin/stanc.exe --name=bernoulli_model[[:space:]]+--O1[[:space:]]+--warn-pedantic[[:space:]]+--o"
} else {
out_w_flags <- "bin/stanc --name='bernoulli_model'[[:space:]]+--O1[[:space:]]+--warn-pedantic[[:space:]]+--o"
out_w_flags <- "bin/stanc --name=bernoulli_model[[:space:]]+--O1[[:space:]]+--warn-pedantic[[:space:]]+--o"
}
expect_output(print(out), out_w_flags)
})
Expand Down
Loading