From a 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 = NULL
)
section_properties_portrait()
section_properties_landscape()
margins_potrait()
margins_landscape()
Arguments
- tt
(
TableTree
or related class)
aTableTree
object representing a populated table.- file
(
string
)
string that indicates the final file output. Must have.docx
extension.- doc_metadata
(
list
ofstring
s)
any value that can be used as metadata by?officer::set_doc_properties
. Important text values aretitle
,subject
,creator
, anddescription
, whilecreated
is a date object.- titles_as_header
(
flag
)
defaults toTRUE
fortt_to_flextable()
, so the table is self-contained as it makes additional header rows forformatters::main_title()
string andformatters::subtitles()
character vector (one per element).FALSE
is suggested forexport_as_docx()
. This adds titles and subtitles as a text paragraph above the table. The same style is applied.- footers_as_text
(
flag
)
defaults toFALSE
fortt_to_flextable()
, so the table is self-contained with theflextable
definition of footnotes.TRUE
is used forexport_as_docx()
to add the footers as a new paragraph after the table. The same style is applied, but with a smaller font.- template_file
(
string
)
template file thatofficer
will 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.
Functions
section_properties_portrait()
: Helper function that defines standard portrait properties for tables.section_properties_landscape()
: Helper function that defines standard landscape 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
. Only the title_as_header
and
footer_as_text
parameters must be re-specified if the table is changed first using tt_to_flextable()
.
Examples
lyt <- basic_table() %>%
split_cols_by("ARM") %>%
analyze(c("AGE", "BMRKR2", "COUNTRY"))
tbl <- build_table(lyt, ex_adsl)
# See how section_properties_portrait function is built for custom
if (FALSE) {
tf <- tempfile(fileext = ".docx")
export_as_docx(tbl, file = tf, section_properties = section_properties_portrait())
}