How to export summary table into word?

Hello all!

I use the package "gtsummary" to produce to look at the balance across treatments in my data frame. However, the result is an image in the viewer. How can I export the result into word to use it directly in my paper?

Below is the command I used for the summary table:

Bal_ana <- data %>% select(a_pri, a_org, a_rfa,a_cfi, ana_pri,ana_org,ana_rfa,ana_cfi,n_ana, Treatment)
Bal_anatable <-
by = Treatment, # split table by group
missing = "no" # don't list missing data separately
) %>%
add_n() %>% # add column with total number of non-missing observations
add_p() %>% # test for a difference between groups
modify_header(label = "Variable") %>% # update the column header

That image is actually HTML you can copy and paste into your word doc.

Borrowing from Rich's comment on a related github issue,

The kableExtra package recommended (01-2018) that the way to get output tables into a Word document is to copy/paste HTML table output from the Viewer directly into an open Word doc.

Another option is to just use the rtf_output format that opens in Word (as an RTF file, which could then be saved as a .docx file, for instance).

The knitr::kable() function is able to produce native table code for Word documents, and, the pander package also has this capability (with more options for table output). Here is a document that describes how: Happy collaboration with Rmd to docx.

Thank you,

I just used the first option, and it works.



You can also save the gtsummary table directly to file (Word, RTF, HTML, PNG, etc)

From the gtsummary website

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.