Skip to contents

From a table, produce a self-contained word document or attach it to a template word file (template_file). This function is based on tt_to_flextable() transformer and 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). A TableTree object representing a populated table.

file

character(1). String that indicates the final file output. It needs to have .docx extension.

doc_metadata

list of character(1)s. Any value that can be used as metadata by ?officer::set_doc_properties. Important text values are title, subject, creator, description while created is a date object.

titles_as_header

logical(1). Defaults to TRUE for tt_to_flextable(), so the table is self-contained as it makes additional header rows for main_title() string and subtitles() character vector (one per element). FALSE is suggested for export_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 for tt_to_flextable(), so the table is self-contained with the flextable definition of footnotes. TRUE is used for export_as_docx() to add the footers as a new paragraph after the table. Same style is applied, but with a smaller font.

template_file

character(1). Template file that officer will use as a starting point for the final document. It will attach the table and use the defaults defined in the template file. Output will be doc file nonetheless.

section_properties

officer::prop_section object. Here you can set 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() does not have many options available. We suggest, if you need specific formats and details to use tt_to_flextable() first and then export_as_docx. Only title_as_header and footer_as_text need to be specified again if changed in 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())
}