brdg_summary {gtsummary} | R Documentation |
Summary table bridge
Description
Bridge function for converting tbl_summary()
(and similar) cards to basic gtsummary objects.
All bridge functions begin with prefix brdg_*()
.
This file also contains helper functions for constructing the bridge,
referred to as the piers (supports for a bridge) and begin with pier_*()
.
-
brdg_summary()
: The bridge function ingests an ARD data frame and returns a gtsummary table that includes.$table_body
and a basic.$table_styling
. The.$table_styling$header
data frame includes the header statistics. Based on context, this function adds a column to the ARD data frame named"gts_column"
. This column is used during the reshaping in thepier_*()
functions defining column names. -
pier_*()
: these functions accept a cards tibble and returns a tibble that is a piece of the.$table_body
. Typically these will be stacked to construct the final table body data frame. The ARD object passed here will have two primary parts: the calculated summary statistics and the attributes ARD. The attributes ARD is used for labeling. The ARD data frame passed to this function must include a"gts_column"
column, which is added inbrdg_summary()
.
Usage
brdg_summary(
cards,
variables,
type,
statistic,
by = NULL,
missing = "no",
missing_stat = "{N_miss}",
missing_text = "Unknown"
)
pier_summary_dichotomous(cards, variables, statistic)
pier_summary_categorical(cards, variables, statistic)
pier_summary_continuous2(cards, variables, statistic)
pier_summary_continuous(cards, variables, statistic)
pier_summary_missing_row(
cards,
variables,
missing = "no",
missing_stat = "{N_miss}",
missing_text = "Unknown"
)
Arguments
cards |
( |
variables |
( |
type |
(named |
statistic |
(named |
by |
( |
missing , missing_text , missing_stat |
Arguments dictating how and if missing values are presented:
|
Value
a gtsummary object
Examples
library(cards)
# first build ARD data frame
cards <-
ard_stack(
mtcars,
ard_continuous(variables = c("mpg", "hp")),
ard_categorical(variables = "cyl"),
ard_dichotomous(variables = "am"),
.missing = TRUE,
.attributes = TRUE
) |>
# this column is used by the `pier_*()` functions
dplyr::mutate(gts_column = ifelse(context == "attributes", NA, "stat_0"))
brdg_summary(
cards = cards,
variables = c("cyl", "am", "mpg", "hp"),
type =
list(
cyl = "categorical",
am = "dichotomous",
mpg = "continuous",
hp = "continuous2"
),
statistic =
list(
cyl = "{n} / {N}",
am = "{n} / {N}",
mpg = "{mean} ({sd})",
hp = c("{median} ({p25}, {p75})", "{mean} ({sd})")
)
) |>
as_tibble()
pier_summary_dichotomous(
cards = cards,
variables = "am",
statistic = list(am = "{n} ({p})")
)
pier_summary_categorical(
cards = cards,
variables = "cyl",
statistic = list(cyl = "{n} ({p})")
)
pier_summary_continuous2(
cards = cards,
variables = "hp",
statistic = list(hp = c("{median}", "{mean}"))
)
pier_summary_continuous(
cards = cards,
variables = "mpg",
statistic = list(mpg = "{median}")
)