Search code examples
kablekableextra

Why does save_kable to PDF result in bad quality PDFs?


Why does save_kable command of the kableExtra package results in bad resolution PDF? I have observed that when a PDF is rendered with magick(which is standard in kableExtra) the quality is pretty bad (see screenshot below). When magick is not installed, it works, but with another renderer (Qt5.5.1 in my case; Macbook Pro 2018, OSX 10.14.6; imagemagick@6 is installed vie brew). However, uninstalling R's magick, rebooting etc. works but is not convenient (especially if you need magick also for other R packages like summarytools) and therefore does not turn out to be a permanent solution. I might handle something not in the way it was intended and I am happy to get some help on this.

Screenshot


Solution

  • Fortunately, I found a solution which looks pretty standard. Simply include density in the save_kable function. This would have save me a lot of time.

     p <- kable(yourdata, escape = F) %>% 
          kable_styling(bootstrap_options = c("condensed"), full_width = F)
     p %>% save_kable("yourdata.pdf", density = 300)