Principally used for export (export_as_docx()
), this function produces a flextable
from an rtables
table. If theme = NULL
, rtables
-like style will be used. Otherwise,
theme_docx_default()
will produce a .docx
-friendly table.
Usage
tt_to_flextable(
tt,
theme = theme_docx_default(tt),
border = flextable::fp_border_default(width = 0.5),
indent_size = NULL,
titles_as_header = TRUE,
footers_as_text = FALSE,
counts_in_newline = FALSE,
paginate = FALSE,
lpp = NULL,
cpp = NULL,
...,
colwidths = propose_column_widths(matrix_form(tt, indent_rownames = TRUE)),
tf_wrap = !is.null(cpp),
max_width = cpp,
total_width = 10
)
theme_docx_default(
tt = NULL,
font = "Arial",
font_size = 9,
bold = c("header", "content_rows", "label_rows"),
bold_manual = NULL,
border = flextable::fp_border_default(width = 0.5)
)
Arguments
- tt
TableTree
(or related class). ATableTree
object representing a populated table.- theme
function(1). Defaults to
theme_docx_default(tt)
. It expects a a theme function that is designed internally as a function of aflextable
object and changes its layout and style. If set toNULL
, it will produce a table similar tortables
default.- border
officer
border object. Defaults toofficer::fp_border(width = 0.5)
.- indent_size
integer(1). If
NULL
, the default indent size of the table (seematrix_form()
indent_size
) is used. To work withdocx
, any size is multiplied by 2 mm (5.67 pt) as default.- titles_as_header
logical(1). Defaults to
TRUE
fortt_to_flextable()
, so the table is self-contained as it makes additional header rows formain_title()
string andsubtitles()
character vector (one per element).FALSE
is suggested forexport_as_docx()
. This adds titles and subtitles as a text paragraph above the table. Same style is applied.- footers_as_text
logical(1). Defaults to
FALSE
fortt_to_flextable()
, so the table is self-contained with the flextable definition of footnotes.TRUE
is used forexport_as_docx()
to add the footers as a new paragraph after the table. Same style is applied, but with a smaller font.- counts_in_newline
logical(1). Defaults to
FALSE
. Inrtables
text printing (formatters::toString()
), the column counts, i.e.(N=xx)
, is always on a new line. We noticed that fordocx
exports could be necessary to have it on the same line.- paginate
logical(1). If you need
.docx
export and you useexport_as_docx
, we suggest relying onword
pagination system. Cooperation between the two mechanisms is not guaranteed. This option splitstt
in different "pages" as multipleflextables
. Defaults toFALSE
.- lpp
numeric. Maximum lines per page including (re)printed header and context rows
- cpp
numeric(1) or NULL. Width (in characters) of the pages for horizontal pagination.
NA
(the default) indicatescpp
should be inferred from the page size;NULL
indicates no horizontal pagination should be done regardless of page size.- ...
Passed on to methods or tabulation functions.
- colwidths
numeric vector. Column widths for use with vertical pagination.
- tf_wrap
logical(1). Should the texts for title, subtitle, and footnotes be wrapped?
- max_width
integer(1), character(1) or NULL. Width that title and footer (including footnotes) materials should be word-wrapped to. If NULL, it is set to the current print width of the session (
getOption("width")
). If set to"auto"
, the width of the table (plus any table inset) is used. Ignored completely iftf_wrap
isFALSE
.- total_width
numeric(1). Total width in inches for the resulting
flextable(s)
. Defaults to 10.- font
character(1). Defaults to
"Arial"
. If the font is not vailable,flextable
default is used.- font_size
integer(1). Positive integerish value that defaults to 9.
- bold
character vector. It can be any combination of
c("header", "content_rows", "label_rows")
. The first one renders all column names bold (nottopleft
content). Second and third option usemake_row_df()
to render content or/and label rows as bold.- bold_manual
named list. List of indexes lists. See example for needed structure. Accepted groupings/names are
c("header", "body")
.
Functions
theme_docx_default()
: main theme function forexport_as_docx()
Examples
analysisfun <- function(x, ...) {
in_rows(
row1 = 5,
row2 = c(1, 2),
.row_footnotes = list(row1 = "row 1 - row footnote"),
.cell_footnotes = list(row2 = "row 2 - cell footnote")
)
}
lyt <- basic_table(
title = "Title says Whaaaat", subtitles = "Oh, ok.",
main_footer = "ha HA! Footer!"
) %>%
split_cols_by("ARM") %>%
analyze("AGE", afun = analysisfun)
tbl <- build_table(lyt, ex_adsl)
# rtables style
tt_to_flextable(tbl, theme = NULL)
Title says Whaaaat
Oh, ok.
A: Drug X
B: Placebo
C: Combination
row1 {1}
5
5
5
row2
1, 2 {2}
1, 2 {3}
1, 2 {4}
{1} - row 1 - row footnote
{2} - row 2 - cell footnote
{3} - row 2 - cell footnote
{4} - row 2 - cell footnote
ha HA! Footer!
tt_to_flextable(tbl, theme = theme_docx_default(tbl, font_size = 7))
Title says Whaaaat
Oh, ok.
A: Drug X
B: Placebo
C: Combination
row1 {1}
5
5
5
row2
1, 2 {2}
1, 2 {3}
1, 2 {4}
{1} - row 1 - row footnote
{2} - row 2 - cell footnote
{3} - row 2 - cell footnote
{4} - row 2 - cell footnote
ha HA! Footer!
# Custom theme
special_bold <- list(
"header" = list("i" = 1, "j" = c(1, 3)),
"body" = list("i" = c(1, 2), "j" = 1)
)
custom_theme <- theme_docx_default(tbl,
font_size = 10,
font = "Brush Script MT",
border = flextable::fp_border_default(color = "pink", width = 2),
bold = NULL,
bold_manual = special_bold
)
tt_to_flextable(tbl,
border = flextable::fp_border_default(color = "pink", width = 2),
theme = custom_theme
)
Title says Whaaaat
Oh, ok.
A: Drug X
B: Placebo
C: Combination
row1 {1}
5
5
5
row2
1, 2 {2}
1, 2 {3}
1, 2 {4}
{1} - row 1 - row footnote
{2} - row 2 - cell footnote
{3} - row 2 - cell footnote
{4} - row 2 - cell footnote
ha HA! Footer!