Skip to content

Commit

Permalink
support tibble::num #257
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-buerkner committed Nov 30, 2022
1 parent f343850 commit 3f89891
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Imports:
checkmate,
rlang (>= 0.4.7),
stats,
tibble (>= 3.0.0),
tibble (>= 3.1.0),
vctrs,
tensorA,
pillar,
Expand Down
10 changes: 9 additions & 1 deletion R/summarise_draws.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#' latter names are used. The functions can be specified in any format
#' supported by [as_function()][rlang::as_function]. See **Examples**.
#' @param .args (named list) Optional arguments passed to the summary functions.
#' @param .num_args (named list) Optional arguments passed to
#' [num()][tibble::num] for pretty printing of summaries.
#' @param .cores (positive integer) The number of cores to use for computing
#' summaries for different variables in parallel. Coerced to integer if
#' possible, otherwise errors. The default is `.cores = 1`, in which case no
Expand Down Expand Up @@ -97,7 +99,8 @@ summarise_draws.default <- function(.x, ...) {

#' @rdname draws_summary
#' @export
summarise_draws.draws <- function(.x, ..., .args = list(), .cores = 1) {
summarise_draws.draws <- function(.x, ..., .args = list(),
.num_args = list(), .cores = 1) {
if (ndraws(.x) == 0L) {
return(empty_draws_summary())
}
Expand Down Expand Up @@ -220,6 +223,11 @@ summarise_draws.draws <- function(.x, ..., .args = list(), .cores = 1) {
}
out <- do.call("rbind", summary_list)
}
for (i in seq_cols(out)) {
if (is.numeric(out[[i]])) {
out[[i]] <- do.call(tibble::num, c(list(out[[i]]), .num_args))
}
}
out
}

Expand Down
5 changes: 4 additions & 1 deletion man/draws_summary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/testthat/test-summarise_draws.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ test_that(paste(
expect_identical(sum_x, parsum_x)
})

test_that("summarise_draws supports tibble::num correctly", {
x <- example_draws()
expect_output(
print(summarise_draws(x, .num_args = list(sigfig = 2, notation="dec"))),
"<dec:2>"
)
})

test_that("summarise_draws errors for invalid cores specification", {
x <- example_draws()
Expand Down

0 comments on commit 3f89891

Please sign in to comment.