ternB: Combine multiple ternD/ternG tables into a single Word...

View source: R/ternB.r

ternBR Documentation

Combine multiple ternD/ternG tables into a single Word document

Description

Takes a list of tibbles previously created by ternD() or ternG() and writes them all into one .docx file, one table per page, preserving the exact formatting settings that were used when each table was built.

Usage

ternB(
  tables,
  output_docx,
  page_break = TRUE,
  methods_doc = FALSE,
  methods_filename = "TernTables_methods.docx"
)

Arguments

tables

A list of tibbles created by ternD() or ternG(). Must be constructed with list(), not c() (e.g. list(T1, T2, T3)). Each tibble must have been produced in the current R session; the metadata is stored in memory, not in the tibble columns.

output_docx

Output file path ending in .docx.

page_break

Logical; if TRUE (default), inserts a page break between each consecutive table.

methods_doc

Logical; if TRUE, writes a single methods section Word document that covers all tables in the list. Statistical test details are pooled across all tables. Default is FALSE.

methods_filename

Output file path for the methods document. Defaults to "TernTables_methods.docx" in the working directory.

Details

ternB() works by replaying the exact word_export() call that ternD() / ternG() would have made – using stored metadata attached as an attribute to each returned tibble – but directing all output into a single combined document instead of separate files.

Table captions (table_caption) and footnotes (table_footnote) specified in the original ternD() / ternG() call are reproduced automatically. You can override them by modifying the "ternB_meta" attribute before calling ternB(), though in practice it is easier to set captions and footnotes when you first build each table.

Value

Invisibly returns the path to the written Word file.

Examples


data(tern_colon)

T1 <- ternD(tern_colon,
            exclude_vars  = "ID",
            table_caption = "Table 1. Overall patient characteristics.",
            methods_doc   = FALSE)

T2 <- ternG(tern_colon,
            group_var     = "Recurrence",
            exclude_vars  = "ID",
            table_caption = "Table 2. Characteristics by recurrence status.",
            methods_doc   = FALSE)

ternB(list(T1, T2),
      output_docx = file.path(tempdir(), "combined_tables.docx"))


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