Some extras for gtsummary tables
sumExtras provides convenience functions for gtsummary and gt tables, including automatic variable labeling from dictionaries, standardized missing value display, and consistent formatting helpers for streamlined table styling workflows.
install.packages("sumExtras")You can install the development version of sumExtras from GitHub:
# install.packages("pak")
pak::pak("kyleGrealis/sumExtras")Alternatively, using remotes:
# install.packages("remotes")
remotes::install_github("kyleGrealis/sumExtras")|
Standard gtsummary workflow trial |>
tbl_summary(by = trt) |>
add_overall() |>
add_p() |>
bold_labels() |>
modify_header(label ~ "") |
Using extras() trial |>
tbl_summary(by = trt) |>
extras() |
|
|
Both produce identical output, but extras() requires significantly less code and ensures consistency across your analysis.
library(sumExtras)
library(gtsummary)
# Apply the recommended JAMA theme (optional but recommended)
use_jama_theme()
# The extras() function - does it all!
trial |>
tbl_summary(by = trt) |>
extras() # Adds overall, p-values, cleans missing values, and more!
# Clean missing values independently
trial |>
tbl_summary(by = trt) |>
clean_table() # Standardizes missing/zero displays to "---"
# With automatic labels from your dictionary
# First, create a dictionary with Variable and Description columns
dictionary <- tibble::tribble(
~Variable, ~Description,
"age", "Age at Enrollment",
"marker", "Marker Level (ng/mL)",
"trt", "Treatment Group",
"grade", "Tumor Grade"
)
trial |>
tbl_summary(by = trt) |>
add_auto_labels() |> # Automatically finds 'dictionary' in your environment
extras()extras()- The signature function that adds overall columns, p-values, and clean stylingclean_table()- Standardizes missing value displayadd_auto_labels()- Smart automatic variable labeling from dictionaries or label attributesapply_labels_from_dictionary()- Set label attributes on data for cross-package workflows (ggplot2, gt, etc.)use_jama_theme()- Apply JAMA compact theme to gtsummary tablestheme_gt_compact()- JAMA-style compact themes for gt tablesgroup_styling()- Enhanced formatting for grouped tables with customizable indentationget_group_rows()- Extract group row information from grouped tables
The labeling functions use the same native R attribute approach as popular packages like haven, Hmisc, and ggplot2 4.0+. Labels are stored as simple 'label' attributes on data columns—no special packages or formats required.
Your data may already have labels from various sources:
- Imported datasets (haven reads SPSS/Stata/SAS labels automatically)
- Other packages that set label attributes
- Manual labeling with
attr(data$column, "label") <- "Label" - Collaborative projects with pre-labeled data
The add_auto_labels() function intelligently reads both dictionary-based labels and existing label attributes from your data, letting you choose which takes precedence. Labels work seamlessly across the entire R ecosystem—compatible with gtsummary, ggplot2, gt, and other label-aware packages.
The extras() function is designed to work with all gtsummary table types using a "warn-and-continue" philosophy:
- It applies all compatible features to your table
- For unsupported features, it issues a helpful warning and continues with what works
- The function always succeeds - it never breaks your pipeline
| Table Type | bold_labels | modify_header | add_overall | add_p | Status |
|---|---|---|---|---|---|
| tbl_summary (stratified) | ✅ | ✅ | ✅ | ✅ | Full support |
| tbl_summary (unstratified) | ✅ | ✅ | Partial support | ||
| tbl_svysummary (stratified) | ✅ | ✅ | ✅ | ✅ | Full support |
| tbl_regression | ✅ | ✅ | Partial support | ||
| tbl_strata | ✅ | ✅ | Partial support |
Legend:
- ✅ Feature works and is applied
⚠️ Feature not applicable to this table type (function warns but continues)
When you call extras() on any table:
- Always applied: Bold labels and clean headers
- Conditionally applied: Overall column and p-values (only on stratified summary tables)
- On unsupported features: You'll see a warning, but the function completes successfully
Example with an unstratified table:
trial |>
tbl_summary() |> # No 'by' argument = unstratified
extras() # Warns that overall/p-values aren't supported, but still bolds labels and cleans headersYou'll see a warning like: "This table is not stratified. Overall column and p-values require stratification. Applying only bold_labels() and modify_header()." - but your table is still successfully formatted!
sumExtras = "SUMmary table EXTRAS" + "SOME EXTRAS for gtSUMMARY"
Get it?
- Bug reports & feature requests: https://github.com/kyleGrealis/sumExtras/issues
- Documentation: See the package vignette with
vignette("sumExtras-intro") - Function help:
?extras?clean_table?add_auto_labels?group_styling?use_jama_theme
- Examples: Run
example(extras)for quick demos
sumExtras is thoroughly tested with:
- 245 test assertions across 7 comprehensive test suites
- Tests covering all core functions and edge cases
- Comprehensive test suites for:
- Main extras functionality (
test-extras.R,test-extras-warnings.R) - Table cleaning and missing value handling (
test-clean_table.R,test-clean_table-regex.R) - Automatic label creation and application (
test-labels.R) - 51 tests covering:- Dictionary auto-discovery and session messaging
- Label priority logic (manual > attributes > dictionary)
- Comprehensive error validation with informative error classes
- Edge cases (NA values, empty/single-row data, long labels)
- All 9 vignette workflow scenarios
- Performance with large dictionaries (1000+ entries) and wide data
- JAMA theme styling (
test-use_jama_theme.R) - Grouped table formatting (
test-styling.R)
- Main extras functionality (
All tests pass with 100% success rate. See the tests directory for detailed test examples and patterns.
We're constantly improving sumExtras. Upcoming feature considerations include:
- Additional gtsummary table type support (tbl_uvregression, tbl_logistic)
- More compact theme options for different journals and styles
- Enhanced dictionary labeling features with validation
- Advanced row grouping and styling customization
We welcome contributions and ideas! Here's how you can help:
- Report bugs - Open an issue with a clear description
- Suggest features - Have an idea? Submit a feature request
- Share feedback - Let us know how sumExtras is working for you
- Improve documentation - Help us make docs clearer and more complete
sumExtras is licensed under the MIT License. See the LICENSE file for details.
sumExtras is built with love using R and these amazing packages:
- gtsummary - Easily create publication-ready analytical tables
- gt - The grammar of tables for R
- dplyr - Data manipulation and transformation
- rlang - Low-level programming tools for R
- purrr - Functional programming tools
Developed by Kyle Grealis
sumExtras adds some extras to your summary tables! ✨

