Reputation: 31
I am trying to run some code, hoping that it will allow me to use kableExtra when knitting to docx:
library(kableExtra)
kable(mtcars, "latex", booktabs = T) %>%
kable_styling(latex_options = c("striped", "scale_down")) %>%
row_spec(1, color = "red") %>%
as_image()
(The code is borrowed here: https://haozhu233.github.io/kableExtra/save_kable_and_as_image.html)
Prior to running the code above, I install ghostscript and these packages (as instructed):
install.packages("magick")
install.packages("webshot")
webshot::install_phantomjs()
When I press knit, I recieve this message:
This is XeTeX, Version 3.14159265-2.6-0.999992 (TeX Live 2020/W32TeX) (preloaded format=xelatex)
restricted \write18 enabled.
entering extended mode
Error in save_kable_latex(x, file, latex_header_includes, keep_tex) : We hit an error when trying to
use magick to read the generated PDF file. You may check your magick installation and try to use
magick::image_read to read the PDF file manually. It's also possible that you didn't have ghostscript
installed.
So, I try to use magick::image_read to read the PDF file manually, Which only results in "R Session Aborted" (the similar function in magick: magick::image_read_pdf works just fine).
How do I solve this?
Upvotes: 3
Views: 498
Reputation: 3252
When I run
```{r}
library(kableExtra)
library(magick)
library(webshot)
webshot::install_phantomjs()
kable(mtcars, "latex", booktabs = T) %>%
kable_styling(latex_options = c("striped", "scale_down")) %>%
row_spec(1, color = "red") %>%
save_kable(file = "tests.pdf")
```
I get the word got without the kable, but I get a .PDF of the filename of the Rmarkdown file. I get the same error trying to replicate the example, I am wondering if there is a broken dependency. What exactly are you trying to do, anything in particular?
Upvotes: 1