Save Input via R markdown.

save_with_rmarkdown(x, path, reference_docx = get_reference_docx("portrait"))

Arguments

x

(gtsummary/gt_tbl/flextable/list)
table object of class 'gtsummary', 'gt_tbl' (gt table) or 'flextable', or a list of table objects.

path

(path)
path to save file to, e.g. "rendered_table.docx"

reference_docx

(path)
Path to reference document that when not NULL is passed to the reference_docx: R markdown field.

Value

x (invisibly)

Examples

# create table
tbl <-
  cards::ADAE[1:150,] |>
  gtsummary::tbl_hierarchical(
    variables = c(AESOC, AETERM),
    by = TRTA,
    denominator = cards::ADSL,
    id = USUBJID,
  )

# save as docx with flextable
gtsummary::as_flex_table(tbl) |>
  flextable::set_table_properties(layout = "autofit") |> # otherwise is going too wide
  save_with_rmarkdown(path = tempfile(fileext = ".docx"))
#>  Writing /tmp/RtmpbBUJrq/file1cce388b1fea.docx

# save as docx with gt
tbl |>
  save_with_rmarkdown(path = tempfile(fileext = ".docx"))
#>  Writing /tmp/RtmpbBUJrq/file1cce539409fa.docx

# split the table and save paginated table
gtsummary::tbl_split_by_rows(tbl, row_numbers = seq(20, nrow(tbl), by = 20)) |>
  save_with_rmarkdown(path = tempfile(fileext = ".docx"))
#>  Writing /tmp/RtmpbBUJrq/file1cce2407fddf.docx