Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Nov 27, 2024
1 parent 6b52af4 commit 287fe66
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: datawizard
Title: Easy Data Wrangling and Statistical Transformations
Version: 0.13.0.14
Version: 0.13.0.15
Authors@R: c(
person("Indrajeet", "Patil", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0003-1995-6531")),
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ CHANGES
* The `replacement` argument in `data_rename()` now supports glue-styled
tokens (#563).

* `data_summary()` also accepts the results of `bayestestR::ci()` as summary
function (#483).

BUG FIXES

* `describe_distribution()` no longer errors if the sample was too sparse to compute
Expand Down
8 changes: 5 additions & 3 deletions R/data_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,15 @@ data_summary.grouped_df <- function(x, ..., by = NULL, remove_na = FALSE) {
}

# check for correct length of output - must be a single value!
if (any(lengths(out) != 1)) {
# Exception: bayestestR::ci()
wrong_length <- !sapply(out, inherits, what = c("bayestestR_ci", "bayestestR_eti")) & lengths(out) != 1 # nolint
if (any(wrong_length)) {
insight::format_error(
paste0(
"Each expression must return a single value. Following expression",
ifelse(sum(lengths(out) != 1) > 1, "s", " "),
ifelse(sum(wrong_length) > 1, "s", " "),
" returned more than one value: ",
text_concatenate(vapply(dots[lengths(out) != 1], insight::safe_deparse, character(1)), enclose = "\"")
text_concatenate(vapply(dots[wrong_length], insight::safe_deparse, character(1)), enclose = "\"")
)
)
}
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test-data_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,26 @@ test_that("data_summary, extra functions", {
out <- data_summary(mtcars, n = n(), by = c("am", "gear"))
expect_identical(out$n, c(15L, 4L, 8L, 5L))
})


test_that("data_summary, bayestestR::ci", {
skip_if_not_installed("bayestesR")
data(mtcars)
out <- data_summary(
mtcars,
mean_value = mean(mpg),
ci = bayestestR::ci(mpg),
by = c("am", "gear")
)
expect_snapshot(out)
expect_error(
data_summary(
mtcars,
mw = mean(mpg),
test = bayestestR::ci(mpg),
yolo = c(mean(mpg), sd(mpg)),
by = c("am", "gear")
),
regex = "Each expression"
)
})

0 comments on commit 287fe66

Please sign in to comment.