Joe
Joe

Reputation: 3806

Prevent long html output from kableExtra::kable_styling() in RStudio

When I use the kableExtra package to produce formatted tables from RStudio, the kable_styling() function produces very long html output below the chunk, which clutters up the notebook. I have tried using message=FALSE and warnings=FALSE as chunk options, but neither prevents these long html messages below the chunk. Are there any other options to prevent these long html messages?

library(dplyr)
library(knitr)
library(kableExtra)

mtcars %>% 
  group_by(cyl, am, vs) %>% 
  summarise(mpg = mean(mpg)) %>% 
  knitr::kable(format = "html") %>% 
  kableExtra::kable_styling()

I have tried installing the development version of kableExtra from github--devtools::install_github("haozhu233/kableExtra")--and this has not fixed the problem.

Upvotes: 0

Views: 446

Answers (1)

mysteRious
mysteRious

Reputation: 4314

Pipe it to invisible() -- you'll have to remove it when you want the HTML to render, but this helps for notebook hygiene along the way (once you know it works).

```{r echo=FALSE, message=FALSE, warning=FALSE}
library(dplyr)
library(knitr)
library(kableExtra)

mtcars %>% 
  group_by(cyl, am, vs) %>% 
  summarise(mpg = mean(mpg)) %>% 
  knitr::kable(format = "html") %>% 
     kableExtra::kable_styling() %>% 
     invisible()
```

Upvotes: 1

Related Questions