as_flextable.TableTree: Transform an rtables object into a flextable

View source: R/as_flextable_rtables.R

as_flextable.TableTreeR Documentation

Transform an rtables object into a flextable

Description

produce a flextable from a TableTree or ElementaryTable object produced with the 'rtables' package.

The conversion uses formatters::matrix_form() to extract the formatted content, column spans, alignments, indentation and footnotes, then maps them to flextable features.

Indentation of row labels is rendered with left padding.

Label rows (LabelRow) are displayed in bold in the first column. Content rows (ContentRow) are displayed entirely in bold.

When LabelRow groups exist, paginate() is applied so that all rows belonging to the same group are kept together on the same page in Word and RTF output.

To paginate the resulting flextable into multiple pages, use split_to_pages(), split_rows(), or split_columns() after calling as_flextable().

Usage

## S3 method for class 'TableTree'
as_flextable(x, indent_padding = 4, ...)

## S3 method for class 'ElementaryTable'
as_flextable(x, indent_padding = 4, ...)

Arguments

x

a TableTree or ElementaryTable object produced by the 'rtables' package.

indent_padding

base left padding in points per indentation level. Default is 4.

...

unused arguments

Value

a flextable object.

See Also

split_to_pages(), split_rows(), split_columns()

Examples

if (require("rtables", character.only = TRUE, quietly = TRUE)) {
  library(rtables)

  lyt <- basic_table(title = "Demographic Summary") %>%
    split_cols_by("ARM") %>%
    split_rows_by("SEX") %>%
    analyze("AGE", afun = mean, format = "xx.x")

  tbl <- build_table(lyt, DM)
  as_flextable(tbl)
}

flextable documentation built on June 2, 2026, 9:08 a.m.