kableExtra package and knitting rnotebook to word file

When I created tables within an rnotebook and used kable on tables, I could knit it into a word document.
However I needed subheadings in between some rows, and resorted to pack_rows from kableExtra library.
This time the word document is not rendered, even though I followed the advice in the error announcement and added " always_allow_html: true":

Error: Functions that produce HTML output found in document targeting docx output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your rmarkdown file:

always_allow_html: true

Does anybody have any idea how to make this knit into a word document?

An example:

library(tidyverse)
library(kableExtra)

table <- mtcars %>% group_by(cyl) %>% summarise(mean(mpg),sd(mpg),IQR(mpg))
table
table <- kable(table) %>% pack_rows("first",1,1) %>% pack_rows("second",2,2) %>% pack_rows("third",3,3)
table

Well, since nobody seems to know better I'll just share what I learned from the net.
Seems kableExtra works only with html output, and it is needed for pack_rows function in my example.
There is flextable package, however it works with somewhat different mechanics and I do not know yet how to make such nice output like with kableExtra.
However, there seem to be two ways here:

  • use flextable (which is touted as multiple output friendly and stable)
  • use kableExtra to make a html document and then copy paste into word - which works quite well.

The choice is yours, then :wink:

1 Like