Save a gt_tbl or gtsummary object as a plain text (Markdown-formatted) file via R markdown. Both gt_tbl objects (from the gt package) and gtsummary objects are supported for plain text output.

save_txt(x, path, encoding = "UTF-8")

Arguments

x

(gt_tbl/gtsummary/list)
object of class 'gt_tbl' (gt table) or 'gtsummary', or a list of such objects. Lists may contain a mix of 'gt_tbl' and 'gtsummary' objects.

path

(path)
path to save file to, e.g. "rendered_table.txt" or "rendered_table.md".

encoding

(string)
character encoding to use when writing the output file. Default is "UTF-8".

Value

(invisibly) a string corresponding to the content of the intermediate .rmd file that is rendered.

Examples

# save a gt table as txt
gt::gt(head(mtcars)) |>
  save_txt(path = tempfile(fileext = ".txt"))
#>  Writing /tmp/RtmpVH4Fyk/file1a96bf9f2f1.txt

# save a gtsummary table as txt
gtsummary::tbl_summary(gtsummary::trial[, c("age", "trt")]) |>
  save_txt(path = tempfile(fileext = ".txt"))
#>  Writing /tmp/RtmpVH4Fyk/file1a967dababaa.txt

# save a list of gt tables as txt — tables are separated by a horizontal rule
list(gt::gt(head(mtcars)), gt::gt(tail(mtcars))) |>
  save_txt(path = tempfile(fileext = ".txt"))
#>  Writing /tmp/RtmpVH4Fyk/file1a96109b85be.txt