Skip to contents

Saves a collection of gtsummary tables and ggplot2 plots into a .docx file.

Usage

save_docx(tables = NULL, plots = NULL, filename = "report.docx", titles = NULL)

Arguments

tables

A list of gtsummary tables.

plots

A list of ggplot2 plot objects.

filename

File name for the output (with or without .docx extension).

titles

Optional. A character vector of titles.

Value

A Word document saved to a temporary directory (if no path is given). No object is returned.

Examples

# \donttest{
library(gtsummary)
library(ggplot2)
tbl <- tbl_regression(glm(mpg ~ hp + wt, data = mtcars))
p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point()
save_docx(
  tables = list(tbl),
  plots = list(p),
  filename = file.path(tempdir(), "report.docx"),
  titles = c("Table 1: Regression", "Figure 1: Scatterplot")
)
#> Word document saved at: /tmp/Rtmp9h6NFv/report.docx
#> If tables or plots extend beyond the page, consider switching to landscape layout in Word (Layout > Orientation > Landscape).
# }