From e4cbb017e549e25b9dec5155a4174b3751a87023 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 8 Jul 2026 20:37:20 +0800 Subject: [PATCH 1/2] Fix accidental mangling of model namespace name --- R/model.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R/model.R b/R/model.R index d807c36a7..2c69fe7c0 100644 --- a/R/model.R +++ b/R/model.R @@ -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"]]) || @@ -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) { @@ -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]], "'")) } } @@ -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( From b9a0c2812a7ad1fa551b254e0a5ef72c187efb8b Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 8 Jul 2026 21:06:43 +0800 Subject: [PATCH 2/2] Update test expectations --- tests/testthat/test-model-compile.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test-model-compile.R b/tests/testthat/test-model-compile.R index bd9b74da9..6d3c4da1c 100644 --- a/tests/testthat/test-model-compile.R +++ b/tests/testthat/test-model-compile.R @@ -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) @@ -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) })