Save as_kable_extra (format = "latex") on file

Viewed 291

I use as_kable_extra(table, format="latex"). This code gives me a chuck of latex codes, then I copy and paste then save it as a tex table.

Can I save the latex code on R so that I can avoid copy and paste?

1 Answers

I would save the table latex code to a file.

library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.4.0'

trial %>%
  select(age, grade) %>%
  tbl_summary() %>%
  as_kable_extra(format = "latex") %>%
  readr::write_lines(file = "latex_table.tex")

Created on 2021-04-29 by the reprex package (v2.0.0)

Then when you're writing your latex document, include the saved latex table using the \input{} command.

\input{latex_table.tex}
Related