Skip to content

Commit 287fe66

Browse files
committed
fix
1 parent 6b52af4 commit 287fe66

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: datawizard
33
Title: Easy Data Wrangling and Statistical Transformations
4-
Version: 0.13.0.14
4+
Version: 0.13.0.15
55
Authors@R: c(
66
person("Indrajeet", "Patil", , "patilindrajeet.science@gmail.com", role = "aut",
77
comment = c(ORCID = "0000-0003-1995-6531")),

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ CHANGES
2525
* The `replacement` argument in `data_rename()` now supports glue-styled
2626
tokens (#563).
2727

28+
* `data_summary()` also accepts the results of `bayestestR::ci()` as summary
29+
function (#483).
30+
2831
BUG FIXES
2932

3033
* `describe_distribution()` no longer errors if the sample was too sparse to compute

R/data_summary.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,15 @@ data_summary.grouped_df <- function(x, ..., by = NULL, remove_na = FALSE) {
196196
}
197197

198198
# check for correct length of output - must be a single value!
199-
if (any(lengths(out) != 1)) {
199+
# Exception: bayestestR::ci()
200+
wrong_length <- !sapply(out, inherits, what = c("bayestestR_ci", "bayestestR_eti")) & lengths(out) != 1 # nolint
201+
if (any(wrong_length)) {
200202
insight::format_error(
201203
paste0(
202204
"Each expression must return a single value. Following expression",
203-
ifelse(sum(lengths(out) != 1) > 1, "s", " "),
205+
ifelse(sum(wrong_length) > 1, "s", " "),
204206
" returned more than one value: ",
205-
text_concatenate(vapply(dots[lengths(out) != 1], insight::safe_deparse, character(1)), enclose = "\"")
207+
text_concatenate(vapply(dots[wrong_length], insight::safe_deparse, character(1)), enclose = "\"")
206208
)
207209
)
208210
}

tests/testthat/test-data_summary.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,26 @@ test_that("data_summary, extra functions", {
228228
out <- data_summary(mtcars, n = n(), by = c("am", "gear"))
229229
expect_identical(out$n, c(15L, 4L, 8L, 5L))
230230
})
231+
232+
233+
test_that("data_summary, bayestestR::ci", {
234+
skip_if_not_installed("bayestesR")
235+
data(mtcars)
236+
out <- data_summary(
237+
mtcars,
238+
mean_value = mean(mpg),
239+
ci = bayestestR::ci(mpg),
240+
by = c("am", "gear")
241+
)
242+
expect_snapshot(out)
243+
expect_error(
244+
data_summary(
245+
mtcars,
246+
mw = mean(mpg),
247+
test = bayestestR::ci(mpg),
248+
yolo = c(mean(mpg), sd(mpg)),
249+
by = c("am", "gear")
250+
),
251+
regex = "Each expression"
252+
)
253+
})

0 commit comments

Comments
 (0)