
Transform an rtables object into a flextable
Source:R/as_flextable_rtables.R
as_flextable.TableTree.Rdproduce 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, ...)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)
}
#>
#> Attaching package: ‘formatters’
#> The following object is masked from ‘package:base’:
#>
#> %||%
#>
#> Attaching package: ‘rtables’
#> The following object is masked from ‘package:utils’:
#>
#> str
Demographic Summary
A: Drug X
B: Placebo
C: Combination
F
mean
33.7
33.8
34.9
M
mean
36.5
32.1
34.3
U
mean
NA
NA
NA
UNDIFFERENTIATED
mean
NA
NA
NA