| ftwrite | R Documentation |
Writes flextable objects to various file formats with optional stamping
(caption with script name, timestamp, and model information). Can write single
flextables or lists of flextables, with automatic file naming and directory
structure organization.
ftwrite(
ft,
file,
formats,
save = TRUE,
show = !save,
quiet = FALSE,
script,
time,
model,
stamp.ft.style,
path.format = NULL,
subdir = NULL,
use.names = TRUE,
stamp.format = NULL,
stamp.funs = NULL,
fun.path = NULL
)
writeFlextab(ft, file, script, formats, save, quiet = FALSE, ...)
ft |
A |
file |
Character string specifying the base file name to save to (without
extension). The actual extension(s) will be determined by the |
formats |
Character vector specifying one or more output formats. Supported
formats are: "png", "docx", "pptx", "html", "rds". Default is |
save |
Logical. Should the table be saved to file? Default is |
show |
Logical. Should the flextable be printed/displayed? Default is the
opposite of |
quiet |
Logical. If |
script |
Character string or path to the script file. If provided, will be included in the table stamp/caption. This helps document which script generated the output. |
time |
Character string or POSIXct timestamp. The default behavior is to
include a timestamp if |
model |
Character string or model object specifying the model name/identifier.
Used for stamping and for organizing output directories via |
stamp.ft.style |
A list of formatting options for the stamp,
passed to |
path.format |
Character string or function defining the output path.
A template using |
subdir |
Character string specifying a subdirectory within the path structure.
Used in conjunction with |
use.names |
Logical. If |
stamp.format |
A template for the stamp text using the
placeholders |
stamp.funs |
Optional named list of functions (elements |
fun.path |
Deprecated. Use |
... |
Additional arguments passed to |
The function handles both single flextable objects and lists of flextables:
For single flextables: writes to file(s) with name specified by file
For lists of flextables: writes each element to a separate file, with names
constructed from file and the list element names
When ft is a list:
Named list elements use their names in the output file names
Unnamed elements are automatically numbered with zero-padded indices
Multiple formats can be written simultaneously by specifying a vector of formats. Each format will be saved as a separate file with the appropriate extension.
Invisibly returns the result from ftwriteOne (for lists,
returns results for all written tables). If show = TRUE, also prints
the flextable(s) to the current device.
writeFlextab(): Deprecated function name. Use ftwrite.
The following formats are supported via the flextable package save functions:
"png": Image format via save_as_image
"docx": Microsoft Word via save_as_docx
"pptx": Microsoft PowerPoint via save_as_pptx
"html": HTML format via save_as_html
"rds": R data format (saves the flextable object itself)
ftwriteOne for writing a single flextable,
ftstamp for adding stamps to flextables,
writer for a unified interface to write various object types,
pathFormat for organizing output directories,
save_as_image,
save_as_docx,
save_as_pptx,
save_as_html
## Not run:
library(flextable)
# Create a simple flextable
ft1 <- flextable(head(mtcars))
# Write to PNG (default format)
ftwrite(ft1, file = "mytable")
# Write to multiple formats
ftwrite(ft1, file = "mytable", formats = c("png", "docx", "html"))
# Write with stamping
ftwrite(ft1, file = "mytable",
script = "analysis.R",
model = "run001")
# Write a list of tables
ft_list <- list(
summary = flextable(summary(mtcars)),
head = flextable(head(mtcars)),
tail = flextable(tail(mtcars))
)
ftwrite(ft_list, file = "tables", formats = "docx")
# Creates: tables_summary.docx, tables_head.docx, tables_tail.docx
# Use with path structure for model organization
ftwrite(ft1, file = "summary",
model = "run001",
path.format = "%model/%name_%model")
# Writes to: run001/summary_run001.png
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.