save_docx: Save Multiple Tables and Plots to a Word Document

View source: R/save_functions.R

save_docxR Documentation

Save Multiple Tables and Plots to a Word Document

Description

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


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")
)


gtregression documentation built on Aug. 18, 2025, 5:23 p.m.