5

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?

AEM
  • 1,354
  • 8
  • 20
  • 30
HSC
  • 129
  • 6

1 Answers1

3

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}
Daniel D. Sjoberg
  • 8,820
  • 2
  • 12
  • 28