Saves a collection of gtregression tables, merged tables,
gt_tbl/flextable objects, and ggplot2 plots into a
single Word document.
Usage
save_docx(
tables = NULL,
plots = NULL,
filename = "report.docx",
titles = NULL,
table_width = 6.5,
plot_width = 6,
plot_height = 5
)Arguments
- tables
A list of tables. Each element may be a
gtregressionobject,merged_tableobject,gt_tbl, orflextable.- plots
A list of
ggplot2plot objects.- filename
File name for the output, with or without
.docx. If no directory is supplied, the file is saved intempdir().- titles
Optional character vector of titles for tables and plots in the order they are added.
- table_width
Maximum table width in inches for Word export. The default
6.5fits a standard portrait Word page with common margins. UseNULLto keep the original flextable widths.- plot_width
Width of inserted plots in inches.
- plot_height
Height of inserted plots in inches.
Examples
birthwt_data <- data_birthwt |>
dplyr::mutate(
smoke = factor(smoke, levels = c(0, 1), labels = c("No", "Yes")),
low = factor(low, levels = c(0, 1), labels = c("Normal BW", "Low BW"))
)
tbl <- uni_reg(
data = birthwt_data,
outcome = "low",
exposures = c("age", "smoke"),
approach = "logit",
format = "flextable"
)
save_docx(tables = tbl, filename = tempfile("report"))
#> Word document saved at: /tmp/RtmplwT6ed/report19c65169dde5.docx