Skip to main content
save_as_rtf() writes one or more flextable objects to an RTF (Rich Text Format) file.

Function signature

save_as_rtf(..., values = NULL, path, pr_section = NULL)

Parameters

...
flextable
required
One or more flextable objects, optionally named. Named objects use the name as a title before the table.
values
list
A list of flextable objects (optionally named). If supplied, ... is ignored.
path
string
required
Path to the .rtf file to create.
pr_section
prop_section
An officer::prop_section object defining page layout properties such as orientation, page size, margins, and optional document headers and footers.

Return value

A string containing the full path of the generated file.

Examples

Save a single table:
library(officer)
ft <- flextable(head(iris))
tf <- tempfile(fileext = ".rtf")
save_as_rtf(ft, path = tf)
Save multiple named tables with a landscape page layout and a custom document header:
library(officer)
ft1 <- flextable(head(iris))
ft2 <- flextable(head(mtcars))

sect_properties <- prop_section(
  page_size = page_size(orient = "landscape", width = 8.3, height = 11.7),
  type = "continuous",
  page_margins = page_mar(),
  header_default = block_list(
    fpar(ftext("text for default page header")),
    qflextable(data.frame(a = 1L))
  )
)

tf <- tempfile(fileext = ".rtf")
save_as_rtf(
  `iris table`   = ft1,
  `mtcars table` = ft2,
  path           = tf,
  pr_section     = sect_properties
)

See also