Learn R Programming

sumExtras (version 0.3.0)

clean_table: Standardize missing value display across all gtsummary table types

Description

Improves table readability by replacing various missing value representations with a consistent "--" symbol. This makes it easier to distinguish between actual data and missing/undefined values in summary tables, creating a cleaner and more professional appearance.

Works seamlessly with all gtsummary table types, including stacked tables (tbl_strata) and survey-weighted summaries (tbl_svysummary). Automatically handles tables with or without the standard var_type column.

Usage

clean_table(tbl)

Value

A gtsummary table object with standardized missing value display

Arguments

tbl

A gtsummary table object (e.g., from tbl_summary(), tbl_svysummary(), tbl_regression(), or tbl_strata())

Details

The function uses gtsummary::modify_table_body() to transform character columns and replace common missing value patterns with "--":

  • "0 (NA%)" - No events occurred and percentages cannot be calculated

  • "NA (NA)" - Completely missing data for both count and percentage

  • "0 (0%)" - Zero counts with zero percentage

  • "0% (0.000)" - Zero percentage with decimal precision

  • "NA (NA, NA)" - Missing data with confidence intervals

  • "NA, NA" - Missing paired values (e.g., median and IQR)

This standardization makes tables more scannable and reduces visual clutter from various "empty" data representations.

Note: The function checks for the presence of var_type column before applying modify_missing_symbol(). This allows it to work seamlessly with tbl_strata objects which use var_type_1, var_type_2, etc. instead of var_type.

See Also

  • gtsummary::modify_table_body() for general table body modifications

  • extras() which includes clean_table() in its styling pipeline

Examples

Run this code
# \donttest{
# Basic usage - clean missing values in summary table
gtsummary::trial |>
  gtsummary::tbl_summary(by = trt) |>
  clean_table()

# Often used as part of a styling pipeline
# Create a test dictionary for add_auto_labels():
dictionary <- tibble::tribble(
  ~Variable, ~Description,
  'age', 'Age at enrollment',
  'stage', 'T Stage',
  'grade', 'Grade',
  'response', 'Tumor Response'
)
gtsummary::trial |>
  gtsummary::tbl_summary(by = trt) |>
  add_auto_labels() |>
  extras() |>
  clean_table()

# Works with regression tables too
lm(age ~ trt + grade, data = gtsummary::trial) |>
  gtsummary::tbl_regression() |>
  clean_table()
# }

Run the code above in your browser using DataLab