After submitting my beautiful tables to a publisher, they want them in either a word or excel file. Is there a simple way to save a gt table to either format or am I better off just redoing them in excel?
Asked
Active
Viewed 4,284 times
4
-
2The `gt::gtsave()` function can save your table in RTF format that is compatible with Word. RTF output is not yet 100% supported and some extra fancy formatting options may not yet be supported. But you'll still get a nice table. – Daniel D. Sjoberg Oct 01 '21 at 12:05
2 Answers
4
Here are some options for exporting gtsummary tables to excel or RTF:
library(gtsummary)
library(writexl)
gt_table <- trial %>%
tbl_summary()
# Export to Excel ----
# convert to tibble, then write to xlsx
gt_table %>%
gtsummary::as_tibble() %>%
writexl::write_xlsx(., "example_gtsummary1.xlsx")
# Or use `as_hux_xlsx()`
gt_table %>%
as_hux_xlsx("example_gtsummary2.xlsx")
# Export to RTF ----
gt_table %>%
gtsummary::as_gt() %>%
gt::gtsave(., "example_gtsummary3.rtf")
More details about the first option in this post: https://www.pipinghotdata.com/posts/2021-07-14-polished-summary-tables-in-r-with-gtsummary/

kittykatstat
- 438
- 2
- 5
1
I've been looking for a solution to this (specifically how to get GT tables into Excel), and I've just discovered that Excel can open HTML tables. So if you don't have lots of tables, you could just export them all as HTML, open them in Excel and then save them as .xlsx files.

Captain Hat
- 2,444
- 1
- 14
- 31