Package 'rtables.officer'

Title: Reporting Tables
Description: Rtables to officer
Authors: Gabriel Becker [ctb], Davide Garolini [aut], Emily de la Rua [aut], Abinaya Yogasekaram [aut], Joe Zhu [aut, cre], F. Hoffmann-La Roche AG [cph, fnd]
Maintainer: Joe Zhu <[email protected]>
License: Apache License 2.0 | file LICENSE
Version: 0.0.1.9003
Built: 2024-11-12 12:33:31 UTC
Source: https://github.com/insightsengineering/rtables.officer

Help Index


Export as word document

Description

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 = section_properties_default(),
  ...
)

section_properties_default(
  page_size = c("letter", "A4"),
  orientation = c("portrait", "landscape")
)

margins_potrait()

margins_landscape()

Arguments

file

(string)
string that indicates the final file output. Must have .docx extension.

doc_metadata

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

template_file

(string)
template file that officer 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)
an officer::prop_section() object which sets margins and page size. Defaults to section_properties_default().

...

(any)
additional arguments passed to tt_to_flextable().

page_size

(character(1)) page size. Can be "letter" or "A4". Defaults to "letter".

orientation

(character(1)) 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. Only the title_as_header and footer_as_text parameters must be re-specified if the table is changed first using tt_to_flextable().

See Also

tt_to_flextable()

Examples

library(flextable)
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
tf <- tempfile(fileext = ".docx")
export_as_docx(tbl,
  file = tf,
  section_properties = section_properties_default(orientation = "landscape")
)

Create enriched flat value table with paths

Description

This function creates a flat tabular file of cell values and corresponding paths via path_enriched_df(). It then writes that data frame out as a tsv file.

Usage

export_as_tsv(
  tt,
  file = NULL,
  path_fun = collapse_path,
  value_fun = collapse_values,
  sep = "\t",
  ...
)

import_from_tsv(file)

Arguments

file

(string)
the path of the file to written to or read from.

sep

(string)
defaults to ⁠\t⁠. See utils::write.table() for more details.

...

(any)
additional arguments to be passed to utils::write.table().

Details

By default (i.e. when value_func is not specified, list columns where at least one value has length > 1 are collapsed to character vectors by collapsing the list element with "|".

Value

  • export_as_tsv returns NULL silently.

  • import_from_tsv returns a data.frame with re-constituted list values.

Note

There is currently no round-trip capability for this type of export. You can read values exported this way back in via import_from_tsv but you will receive only the data.frame version back, NOT a TableTree.

See Also

path_enriched_df() for the underlying function that does the work.