Saves a gtregression table, merged table, gt_tbl, or
flextable as a Word, PDF, or HTML file.
Arguments
- tbl
A
gtregressionobject,merged_tableobject,gt_tbl, orflextable.- filename
File name for the output. Extension is optional. If no directory is supplied, the file is saved in
tempdir().- format
Output format. One of
"docx","pdf", or"html".- orientation
Word page orientation for DOCX output. One of
"auto","portrait", or"landscape". With"auto", wide tables are saved in landscape orientation before any font-size reduction is attempted.- fit_width
Logical. If
TRUE, try to fit flextable DOCX output within the selected Word page width. IfFALSE, keep the natural autofit table width.- font_size
Requested font size for flextable DOCX output.
- min_font_size
Smallest font size allowed when fitting wide flextable DOCX output. The font size is never reduced below this value.
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"
)
save_table(tbl, filename = tempfile("table"), format = "html")
#> Table saved at: /tmp/RtmplwT6ed/table19c64749240.html
# Wide Word tables can be saved in landscape orientation.
# \donttest{
save_table(
tbl,
filename = tempfile("table-wide"),
format = "docx",
orientation = "auto",
fit_width = TRUE,
font_size = 9,
min_font_size = 8
)
#> Table saved at: /tmp/RtmplwT6ed/table-wide19c64ea62fc0.docx
# }