Skip to content

Commit

Permalink
Printing improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Nov 6, 2024
1 parent 48d4276 commit da9b115
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/progress.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ progress_bar_fancy <- function(n_chains, n_steps, show_overall,
"{cli::pb_percent} ETA: {cli::pb_eta}")
fmt_done <- paste(
"{cli::col_green(cli::symbol$tick)} Sampled {cli::pb_total} steps",
"across {n_chains} chains in {cli::pb_elapsed}")
"across {n_chains} chain{?s} in {cli::pb_elapsed}")
fmt_failed <- paste(
"{cli::col_red(cli::symbol$cross)} Sampling stopped at {cli::pb_current}",
"step{?s} after {cli::pb_elapsed}")
Expand Down
4 changes: 4 additions & 0 deletions R/samples.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ print.monty_samples <- function(x, ...) {
cli::cli_alert_info(
"These samples can be restared with {.help monty_sample_continue}")
}
if (!is.null(x$observations)) {
cli::cli_alert_info(
"These samples have associated observations")
}

cli::cli_alert_info(
paste('See {.help monty_sample} and {.run vignette("samples")} for more',
Expand Down
40 changes: 40 additions & 0 deletions tests/testthat/test-samples.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,46 @@ test_that("can print samples", {
})


test_that("print information about observations", {
model <- ex_simple_gamma1()
sampler <- monty_sampler_random_walk(vcv = diag(1) * 0.01)
s <- monty_sample(model, sampler, 100, 1, n_chains = 3)

res <- evaluate_promise(print(s))
expect_no_match(
res$messages,
"These samples have associated observations",
fixed = TRUE, all = FALSE)

s$observations <- list(a = 1)
res <- evaluate_promise(print(s))
expect_match(
res$messages,
"These samples have associated observations",
fixed = TRUE, all = FALSE)
})


test_that("print information about restart", {
model <- ex_simple_gamma1()
sampler <- monty_sampler_random_walk(vcv = diag(1) * 0.01)
s <- monty_sample(model, sampler, 100, 1, n_chains = 3)

res <- evaluate_promise(print(s))
expect_no_match(
res$messages,
"These samples can be restared with",
fixed = TRUE, all = FALSE)

s$restart <- list()
res <- evaluate_promise(print(s))
expect_match(
res$messages,
"These samples can be restared with",
fixed = TRUE, all = FALSE)
})


test_that("can convert to posterior draws types", {
skip_if_not_installed("posterior")
model <- ex_simple_gamma1()
Expand Down

0 comments on commit da9b115

Please sign in to comment.