| ternD | R Documentation |
Creates a descriptive summary table with a single "Total" column format.
By default (consider_normality = "ROBUST"), continuous variables are shown
as mean +/- SD or median [IQR] based on a four-gate decision (n < 3 fail-safe, skewness, CLT, and Shapiro-Wilk).
This can be overridden via consider_normality and force_ordinal.
ternD(
data,
vars = NULL,
exclude_vars = NULL,
force_ordinal = NULL,
output_xlsx = NULL,
output_docx = NULL,
consider_normality = "ROBUST",
print_normality = FALSE,
round_intg = FALSE,
smart_rename = TRUE,
insert_subheads = TRUE,
factor_order = "mixed",
methods_doc = TRUE,
methods_filename = "TernTables_methods.docx",
category_start = NULL,
table_font_size = 9,
manual_italic_indent = NULL,
manual_underline = NULL,
table_caption = NULL,
table_footnote = NULL,
line_break_header = getOption("TernTables.line_break_header", TRUE)
)
data |
Tibble with variables. |
vars |
Character vector of variables to summarize. Defaults to all except |
exclude_vars |
Character vector to exclude from the summary. |
force_ordinal |
Character vector of variables to treat as ordinal (i.e., use median [IQR])
regardless of the |
output_xlsx |
Optional Excel filename to export the table. |
output_docx |
Optional Word filename to export the table. |
consider_normality |
Character or logical; controls routing of continuous variables to
mean |
print_normality |
Logical; if |
round_intg |
Logical; if |
smart_rename |
Logical; if |
insert_subheads |
Logical; if |
factor_order |
Character; controls the ordering of factor levels in the output.
|
methods_doc |
Logical; if |
methods_filename |
Character; filename for the methods document.
Default is |
category_start |
Named character vector specifying where to insert category headers.
Names are the header label text to display; values are the anchor variable – either the
original column name (e.g. |
table_font_size |
Numeric; font size for Word document output tables. Default is 9. |
manual_italic_indent |
Character vector of display variable names (post-cleaning) that should be
formatted as italicized and indented in Word output – matching the appearance of factor sub-category
rows. Has no effect on the returned tibble; only applies when |
manual_underline |
Character vector of display variable names (post-cleaning) that should be
formatted as underlined in Word output – matching the appearance of multi-category variable headers.
Has no effect on the returned tibble; only applies when |
table_caption |
Optional character string for a table caption to display above the table in
the Word document. Rendered as size 11 Arial bold, single-spaced with a small gap before the table.
Default is |
table_footnote |
Optional character string for a footnote to display below the table in the
Word document. Rendered as size 6 Arial italic with a double-bar border above and below.
Default is |
line_break_header |
Logical; if |
The function always returns a tibble with a single Total (N = n) column format, regardless of the
consider_normality setting. The behavior for numeric variables follows this priority:
Variables in force_ordinal: Always use median [IQR]
When consider_normality = "ROBUST": Four-gate decision (n<3 fail-safe, skewness, CLT, Shapiro-Wilk)
When consider_normality = TRUE: Use Shapiro-Wilk test to choose format
When consider_normality = FALSE: Default to mean +/- SD
For categorical variables, the function shows frequencies and percentages. When
insert_subheads = TRUE, categorical variables with 3 or more levels are displayed with
hierarchical formatting (main variable as header, levels as indented sub-rows). Binary variables
(Y/N, YES/NO, or numeric 1/0 auto-detected as Y/N) always use a single-row format showing
only the positive/yes count, regardless of this setting. Two-level categorical variables whose
values are not Y/N, YES/NO, or 1/0 (e.g. Male/Female) also use the hierarchical sub-row format.
A tibble with one row per variable (multi-row for factors), containing:
Variable names with appropriate indentation
Summary statistics (mean +/- SD, median [IQR], or n (%) as appropriate)
Shapiro-Wilk P values (only if print_normality = TRUE)
data(tern_colon)
# Basic descriptive summary
ternD(tern_colon, exclude_vars = c("ID"), methods_doc = FALSE)
# With normality-aware formatting and category section headers
ternD(tern_colon, exclude_vars = c("ID"), methods_doc = FALSE,
category_start = c("Patient Demographics" = "Age (yr)",
"Tumor Characteristics" = "Positive Lymph Nodes (n)"))
# Force specific variables to ordinal (median [IQR]) display
ternD(tern_colon, exclude_vars = c("ID"), methods_doc = FALSE,
force_ordinal = c("Positive_Lymph_Nodes_n"))
# Export to Word (writes a file to tempdir)
ternD(tern_colon,
exclude_vars = c("ID"),
methods_doc = FALSE,
output_docx = file.path(tempdir(), "descriptive.docx"),
category_start = c("Patient Demographics" = "Age (yr)",
"Surgical Findings" = "Colonic Obstruction",
"Tumor Characteristics" = "Positive Lymph Nodes (n)",
"Outcomes" = "Recurrence"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.