From an rtables table, produce a self-contained Word document or attach it to a template Word
file (template_file). This function is based on the tt_to_flextable() transformer and
the officer package.
Usage
export_as_docx(
tt,
file,
doc_metadata = NULL,
titles_as_header = FALSE,
footers_as_text = TRUE,
template_file = NULL,
section_properties = section_properties_default(),
...
)
section_properties_default(
page_size = c("letter", "A4"),
orientation = c("portrait", "landscape")
)
margins_potrait()
margins_landscape()Arguments
- tt
(
TableTreeor related class)
aTableTreeobject representing a populated table.- file
(
string)
output file. Must have.docxextension.- doc_metadata
(
listofstring)
any value that can be used as metadata byofficer::set_doc_properties(). Important text values aretitle,subject,creator, anddescription, whilecreatedis a date object.- titles_as_header
(
flag)
whether the table should be self-contained with additional header rows created for titles and subtitles (TRUE), or titles and subtitles should be added as a paragraph of text above the table (FALSE). Defaults toFALSE.(
flag)
whether footers should be added as a new paragraph after the table (TRUE) or the table should be self-contained, implementingflextable-style footnotes (FALSE) with the same style but a smaller font. Defaults toTRUE.- template_file
(
string)
template file thatofficerwill use as a starting point for the final document. Document attaches the table and uses the defaults defined in the template file.- section_properties
(
officer::prop_section)
anofficer::prop_section()object which sets margins and page size. Defaults tosection_properties_default().- ...
(
any)
additional arguments passed tott_to_flextable().- page_size
(
string) page size. Can be"letter"or"A4". Defaults to"letter".- orientation
(
string) page orientation. Can be"portrait"or"landscape". Defaults to"portrait".
Functions
section_properties_default(): Helper function that defines standard portrait properties for tables.margins_potrait(): Helper function that defines standard portrait margins for tables.margins_landscape(): Helper function that defines standard landscape margins for tables.
Note
export_as_docx() has few customization options available. If you require specific formats and details,
we suggest that you use tt_to_flextable() prior to export_as_docx(). If the table is modified first using
tt_to_flextable(), the titles_as_header and footer_as_text parameters must be re-specified.
Examples
lyt <- basic_table() %>%
split_cols_by("ARM") %>%
analyze(c("AGE", "BMRKR2", "COUNTRY"))
tbl <- build_table(lyt, ex_adsl)
# See how the section_properties_portrait() function is built for customization
tf <- tempfile(fileext = ".docx")
export_as_docx(tbl,
file = tf,
section_properties = section_properties_default(orientation = "landscape")
)
