Skip to content

Commit b6ade07

Browse files
authored
Merge pull request #1142 from stan-dev/fix-1140-add-missing-arguments
add show_messages and show_exceptions to generate_quantities
2 parents f429f12 + 43270b5 commit b6ade07

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

R/model.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,12 +2001,16 @@ generate_quantities <- function(fitted_params,
20012001
sig_figs = NULL,
20022002
parallel_chains = getOption("mc.cores", 1),
20032003
threads_per_chain = NULL,
2004-
opencl_ids = NULL) {
2004+
opencl_ids = NULL,
2005+
show_messages = TRUE,
2006+
show_exceptions = TRUE) {
20052007
fitted_params_files <- process_fitted_params(fitted_params)
20062008
procs <- CmdStanGQProcs$new(
20072009
num_procs = length(fitted_params_files),
20082010
parallel_procs = checkmate::assert_integerish(parallel_chains, lower = 1, null.ok = TRUE),
2009-
threads_per_proc = assert_valid_threads(threads_per_chain, self$cpp_options(), multiple_chains = TRUE)
2011+
threads_per_proc = assert_valid_threads(threads_per_chain, self$cpp_options(), multiple_chains = TRUE),
2012+
show_stderr_messages = show_exceptions,
2013+
show_stdout_messages = show_messages
20102014
)
20112015
model_variables <- NULL
20122016
if (is_variables_method_supported(self)) {

man/model-method-generate-quantities.Rd

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-model-generate_quantities.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,14 @@ test_that("generate_quantities() warns if threads specified but not enabled", {
9292
"'threads_per_chain' will have no effect"
9393
)
9494
})
95+
96+
test_that("no output with show_messages = FALSE", {
97+
output <- utils::capture.output(
98+
fit_gq <- mod_gq$generate_quantities(
99+
fitted_params = fit,
100+
data = data_list,
101+
show_messages = FALSE
102+
)
103+
)
104+
expect_equal(length(output), 0)
105+
})

tests/testthat/test-model-pathfinder.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,10 @@ test_that("no error when checking estimates after failure", {
150150
expect_silent(fit$summary()) # no error
151151
})
152152

153+
test_that("no output with show_messages = FALSE", {
154+
output <- utils::capture.output(
155+
fit <- mod$pathfinder(data = data_list, show_messages = FALSE, seed = 123)
156+
)
157+
expect_equal(length(output), 0)
158+
})
159+

0 commit comments

Comments
 (0)