Generates a formatted summary table comparing baseline characteristics between treatment arms. Supports continuous, categorical, and binary variables with p-values, standardized mean differences (SMD), and missing data summaries.
create_summary_table(
data,
treat_var = "treat",
vars_continuous = NULL,
vars_categorical = NULL,
vars_binary = NULL,
var_labels = NULL,
digits = 1,
show_pvalue = TRUE,
show_smd = TRUE,
show_missing = TRUE,
table_title = "Baseline Characteristics by Treatment Arm",
table_subtitle = NULL,
source_note = NULL,
font_size = 12,
header_font_size = 14,
footnote_font_size = 10,
use_alternating_rows = TRUE,
stripe_color = "#f9f9f9",
indent_size = 20,
highlight_pval = 0.05,
highlight_smd = 0.2,
highlight_color = "#fff3cd",
compact_mode = FALSE,
column_width_var = 200,
column_width_stats = 120,
show_column_borders = FALSE,
custom_css = NULL
)A gt table object (or data frame if gt not available)
Data frame containing the analysis data
Character. Name of treatment variable (must have 2 levels)
Character vector. Names of continuous variables
Character vector. Names of categorical variables
Character vector. Names of binary (0/1) variables
Named list. Custom labels for variables (optional)
Integer. Number of decimal places for continuous variables
Logical. Include p-values column
Logical. Include SMD (effect size) column
Logical. Include missing data rows
Character. Main title for the table
Character. Subtitle for the table (optional)
Character. Source note at bottom (optional)
Numeric. Base font size in pixels (default: 12)
Numeric. Header font size in pixels (default: 14)
Numeric. Footnote font size in pixels (default: 10)
Logical. Apply zebra striping (default: TRUE)
Character. Color for alternating rows (default: "#f9f9f9")
Numeric. Indentation for sub-levels in pixels (default: 20)
Numeric. Highlight p-values below this threshold (default: 0.05)
Numeric. Highlight SMD values above this threshold (default: 0.2)
Character. Color for highlighting (default: "#fff3cd")
Logical. Reduce spacing for compact display (default: FALSE)
Numeric. Width for Variable column in pixels (default: 200)
Numeric. Width for stat columns in pixels (default: 120)
Logical. Show vertical column borders (default: FALSE)
Character. Additional custom CSS styling (optional)
Binary variables specified via vars_binary display a single row
showing the count and proportion for the "1" level. Categorical variables
specified via vars_categorical that happen to be binary-coded (i.e.,
have exactly two levels: 0 and 1) are automatically detected and displayed
in the same compact single-row format, showing only the "1" proportion.