Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data_summary() works with bayestestR::ci() #483

Merged
merged 27 commits into from
Nov 27, 2024
Merged
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions R/data_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ data_summary.data.frame <- function(x, ..., by = NULL, remove_na = FALSE) {
# bind grouping-variables and values
summarised_data <- cbind(s[1, by], summarised_data)
# make sure we have proper column names
colnames(summarised_data) <- c(by, vapply(summarise, names, character(1)))
colnames(summarised_data) <- c(by, unlist(lapply(summarise, names)))
etiennebacher marked this conversation as resolved.
Show resolved Hide resolved
summarised_data
})
out <- do.call(rbind, out)
Expand Down Expand Up @@ -187,7 +187,11 @@ data_summary.grouped_df <- function(x, ..., by = NULL, remove_na = FALSE) {

out <- lapply(seq_along(dots), function(i) {
new_variable <- .get_new_dots_variable(dots, i, data)
stats::setNames(new_variable, names(dots)[i])
if (inherits(new_variable, c("bayestestR_ci", "bayestestR_eti"))) {
stats::setNames(new_variable, c("CI", "CI_low", "CI_high"))
} else {
stats::setNames(new_variable, names(dots)[i])
}
})
}

Expand All @@ -214,6 +218,11 @@ print.dw_data_summary <- function(x, ...) {
if (nrow(x) == 0) {
cat("No matches found.\n")
} else {
if (all(c("CI", "CI_low", "CI_high") %in% colnames(x))) {
ci <- insight::format_table(x[c("CI", "CI_low", "CI_high")], ...)
x$CI <- x$CI_low <- x$CI_high <- NULL
x <- cbind(x, ci)
}
strengejacke marked this conversation as resolved.
Show resolved Hide resolved
cat(insight::export_table(x, missing = "<NA>", ...))
}
}
Loading