word_export: Export TernTables output to a formatted Word document

View source: R/export_to_word.R

word_exportR Documentation

Export TernTables output to a formatted Word document

Description

Export TernTables output to a formatted Word document

Usage

word_export(
  tbl,
  filename,
  round_intg = FALSE,
  font_size = 9,
  category_start = NULL,
  manual_italic_indent = NULL,
  manual_underline = NULL,
  table_caption = NULL,
  table_footnote = NULL,
  line_break_header = getOption("TernTables.line_break_header", TRUE)
)

Arguments

tbl

A tibble created by ternG or ternD

filename

Output file path ending in .docx

round_intg

Logical; if TRUE, adds note about integer rounding. Default is FALSE.

font_size

Numeric; font size for table body. Default is 9.

category_start

Named character vector specifying category headers. Names are header label text; values are anchor variable names – either the original column name or the cleaned display name (both forms accepted).

manual_italic_indent

Character vector of display variable names (post-cleaning) to force into italicized and indented formatting, matching the appearance of factor sub-category rows (e.g., levels of a multi-category variable). Use this for rows that should visually appear as sub-items but are not automatically detected as such.

manual_underline

Character vector of display variable names (post-cleaning) to force into underlined formatting, matching the appearance of multi-category variable header rows. Use this for rows that should visually appear as section headers but are not automatically detected as such.

table_caption

Optional character string to display as a caption above the table in the Word document. Rendered as size 11 Arial bold, single-spaced with a small gap before the table. Default is NULL (no caption).

table_footnote

Optional character string to display as a footnote below the table in the Word document. Rendered as size 6 Arial italic. A double-bar border is applied above and below the footnote row. Default is NULL (no footnote).

line_break_header

Logical; if TRUE (default), column headers are wrapped with \n – group names break on spaces, sample size counts move to a second line, and the first column header includes a category hierarchy label. Set to FALSE to suppress all header line breaks. Can also be set package-wide via options(TernTables.line_break_header = FALSE).

Value

Invisibly returns the path to the written Word file.

Examples


data(tern_colon)
tbl <- ternD(tern_colon, exclude_vars = c("ID"), methods_doc = FALSE)
word_export(
  tbl      = tbl,
  filename = file.path(tempdir(), "descriptive.docx"),
  category_start = c(
    "Patient Demographics"  = "Age (yr)",
    "Tumor Characteristics" = "Positive Lymph Nodes (n)"
  )
)


TernTables documentation built on March 26, 2026, 5:09 p.m.