Skip to content

Commit

Permalink
Adding tbl_summary(percent) argument (#1585)
Browse files Browse the repository at this point in the history
* updates

* updates
  • Loading branch information
ddsjoberg authored Jan 13, 2024
1 parent 0ea2bfc commit b94919d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Depends:
R (>= 4.1)
Imports:
broom.helpers,
cards (>= 0.0.0.9009),
cards (>= 0.0.0.9010),
cli (>= 3.6.1),
dplyr (>= 1.1.3),
glue (>= 1.6.2),
Expand Down
17 changes: 9 additions & 8 deletions R/bridge_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pier_summary_dichotomous <- function(x, variables, value = x$inputs$value) {
.data$variable_level %in% list(NULL) |
.data$variable_level %in% list(value[[.data$variable[1]]])
) |>
# updating the context to continuous, because it will be process that way below
# updating the context to continuous, because it will be processed that way below
dplyr::mutate(
context = ifelse(.data$context %in% "categorical", "continuous", .data$context)
)
Expand Down Expand Up @@ -169,8 +169,7 @@ pier_summary_categorical <- function(x, variables, missing, missing_text, missin
cards::get_ard_statistics(
df_variable_stats,
.data$variable_level %in% list(NULL),
.column = "statistic_fmt",
.attributes = NULL
.column = "statistic_fmt"
)

str_statistic_pre_glue <-
Expand All @@ -193,7 +192,7 @@ pier_summary_categorical <- function(x, variables, missing, missing_text, missin
glue::glue(
str_to_glue,
.envir =
cards::get_ard_statistics(df_variable_level_stats, .column = "statistic_fmt", .attributes = NULL) |>
cards::get_ard_statistics(df_variable_level_stats, .column = "statistic_fmt") |>
c(lst_variable_stats)
) |>
as.character()
Expand Down Expand Up @@ -286,7 +285,7 @@ pier_summary_continuous2 <- function(x, variables, missing, missing_text, missin
stat =
glue::glue(
str_to_glue,
.envir = cards::get_ard_statistics(.x, .column = "statistic_fmt", .attributes = NULL)
.envir = cards::get_ard_statistics(.x, .column = "statistic_fmt")
) |>
as.character()
}
Expand All @@ -299,7 +298,7 @@ pier_summary_continuous2 <- function(x, variables, missing, missing_text, missin
label =
glue::glue(
str_to_glue,
.envir = cards::get_ard_statistics(.x, .column = "stat_label", .attributes = NULL)
.envir = cards::get_ard_statistics(.x, .column = "stat_label")
) |>
as.character()
}
Expand Down Expand Up @@ -362,6 +361,7 @@ pier_summary_continuous2 <- function(x, variables, missing, missing_text, missin
#' @rdname bridge_summary
#' @export
pier_summary_continuous <- function(x, variables, missing, missing_text, missing_stat) {
if (is_empty(variables)) return(dplyr::tibble())
# subsetting cards object on continuous summaries ----------------------------
card <-
x$cards |>
Expand All @@ -379,7 +379,7 @@ pier_summary_continuous <- function(x, variables, missing, missing_text, missing
stat =
glue::glue(
x$inputs$statistic[[.data$variable[1]]],
.envir = cards::get_ard_statistics(.x, .column = "statistic_fmt", .attributes = NULL)
.envir = cards::get_ard_statistics(.x, .column = "statistic_fmt")
) |>
as.character()
)
Expand Down Expand Up @@ -502,7 +502,8 @@ pier_summary_missing_row <- function(x, variables = x$inputs$include) {
df_by_stats |>
dplyr::filter(.data$stat_name %in% "N") |>
dplyr::pull("statistic") |>
unlist()
unlist() |>
getElement(1L)
) |>
dplyr::left_join(
df_by_stats_wide,
Expand Down
9 changes: 5 additions & 4 deletions R/tbl_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,15 @@ tbl_summary <- function(data,
# tabulate categorical summaries
cards::ard_categorical(
data,
by = by,
variables = .get_variables_by_type(type, c("categorical", "dichotomous")),
fmt_fn = digits
by = all_of(by),
variables = all_of(.get_variables_by_type(type, c("categorical", "dichotomous"))),
fmt_fn = digits,
denominator = percent
),
# calculate categorical summaries
cards::ard_continuous(
data,
by = by,
by = all_of(by),
variables = .get_variables_by_type(type, c("continuous", "continuous2")),
fmt_fn = digits
)
Expand Down

0 comments on commit b94919d

Please sign in to comment.