rknitrkableextrapkgdown

Supress long html output with kable_styling


One of the functions in my package produces a table using kable() and kable_styling(). When I run this code, I see both the output in the viewer and the long HTML code in the console. I see solutions for excluding the HTML output in an Rmd but not for a function. It also only displays the code when I use pkgdown::build_site()

I have tried invisible(), sink() and I'm using the latest version of kableExtra (1.1.0)

How can I get it to only show the result in the viewer and also show up correctly in the function's reference page?

I'm not sure how to reprex the pkgdown stuff but this should be enough to make some headway.

library(tidyverse)
library(knitr)
library(kableExtra)

mpg %>% 
  kable(format = "html") %>% 
  kable_styling()

# same result
x <- mpg %>% kable(format = "html")

kable_styling(x)

enter image description here


Solution

  • You can use capture.output to stop printing the output in console but still displaying it in viewer.

    x <- mpg %>% kable(format = "html") %>% kable_styling() %>% capture.output()