6

Is there a way to export or knit a table directly to word-format in an R-script (instead of R-markdown)? knitr and kableExtra seem to provide a wide range of options to save tables, yet there is no option to export tables as actual word files.

library(tidyverse)
library(kableExtra)

dt <- mtcars[1:5, 1:6]

kbl(dt, caption="Table") %>%
  kable_classic(full_width = F, html_font = "Cambria")
  save_kable("my_latex_table.png") # alternatives: .jpg and .pdf, but not .doc

Since packages and functions such as htmlreg::texreg() allow you to write the output of statistical models into nicely formatted tables which you can then directly include into word documents, I would imagine that this should also be possible with simple tables (e.g. descriptive statistics). The thing is that I would like to export them directly in the format of a word table instead of an image.

Dr. Fabian Habersack
  • 1,111
  • 12
  • 30
  • 1
    If you created an R Markdown document as a word document output and the contents were only your table, that seems like it would meet your needs. – TTS Sep 24 '20 at 15:16
  • It does indeed, but I was wondering if that is really necessary. Intuitively, I thought there should be a way to get the same result in a simple R script without having to create an .Rmd just for this purpose. – Dr. Fabian Habersack Sep 28 '20 at 15:39

1 Answers1

0

After 4h of trying things and packages, I finally stumbled across this minimalistically documented function of the repmod package: make_word_table. Is that what you are looking for?

lilla
  • 151
  • 3
  • 12