R/customize_table.R
customize_table.RdThis function customizes a gtsummary summary table by adding an overall column,
handling missing data, applying group-specific statistics, and updating headers
and captions. It provides flexible options for grouping, displaying missing data,
and customizing table titles.
customize_table(
base_table,
by_group = FALSE,
var_group,
add_total,
show_missing_data,
show_n_per_group,
group_title,
table_title,
var_title,
var_tot = NULL,
var_characteristic = NULL
)A gtsummary table object, typically generated using functions
like gtsummary::tbl_summary.
A boolean (default is FALSE) to analyse by group.
A string or NULL, specifying the variable used for grouping in the
table. If NULL, no group-specific modifications are applied.
A boolean to add total column or not when var_group is specified.
A boolean indicating whether to display missing data counts
and percentages in the table. If TRUE, columns for missing data will be added.
A boolean indicating whether to display group sizes (n) for each level of the grouping variable.
A string specifying the title for the group column in the table.
A string specifying the title of the entire table.
A string specifying the title for the variable column in the table.
A string specifying the name of total column. Default is NULL and will guess from theme_gtsummary_language().
A string specifying the name of characteristic column. Default is NULL and will guess from theme_gtsummary_language().
A customized gtsummary table object with added columns, headers, captions,
and modifications based on the provided arguments.
The show_missing_data parameter determines whether missing data counts and
percentages are displayed:
If TRUE, missing data columns are added.
If FALSE, only non-missing data counts are displayed.
Headers for columns and spanning headers are customized using the group_title,
table_title, and var_title arguments.
An external function modify_table_body_func is called to further modify
the table body.
# Example usage with a sample gtsummary table
library(gtsummary)
#> Warning: package 'gtsummary' was built under R version 4.4.3
base_table <- trial %>%
tbl_summary(by = "trt", missing = "no")
customize_table(
base_table,
var_group = "trt",
add_total = TRUE,
show_missing_data = TRUE,
show_n_per_group = FALSE,
group_title = "Treatment Group",
table_title = "Summary Statistics",
var_title = "Variables",
var_tot = "Total"
)
Summary Statistics
Characteristic
N
Drug A
Drug B