How to save a table as an image but also preserve its quality? R

Viewed 6097

Looking for tips to save a table as an image with the quality seen in the RStudio Viewer. I've tried save_kable and as_image but both resulted in serious drops in quality.

Any other recommendations?

Code for reference:

library(htmlTable)
library(xtable)
library(kableExtra)
data(tli)
htmlTable(xtable(tli[1:10,),rnames=FALSE)%>%save_kable('table.png')`
1 Answers

The save_kable function has a ... argument which passes variables to webshot::webshot.

From the webshot README, you can generate higher quality screenshots with the zoom option, e.g.,

library(knitr)
library(kableExtra)
library(magrittr)

kable(iris[1:10,]) %>%
  kable_styling() %>%
  save_kable(file = "table_1.png")

kable(iris[1:10,]) %>%
  kable_styling() %>%
  save_kable(file = "table_2.png",
             zoom = 1.5)
Related