【问题标题】:Trouble with Rmarkdown, when trying to use kableExtra::kable with as_image(), to generate a table in Word当尝试将 kableExtra::kable 与 as_image() 一起使用时,Rmarkdown 出现问题,以在 Word 中生成表格
【发布时间】:2020-07-09 16:24:06
【问题描述】:

我正在尝试运行一些代码,希望它能让我在编织到 docx 时使用 kableExtra:

library(kableExtra)

kable(mtcars, "latex", booktabs = T) %>%
kable_styling(latex_options = c("striped", "scale_down")) %>%
row_spec(1, color = "red") %>%
as_image()

(此处借用代码:https://haozhu233.github.io/kableExtra/save_kable_and_as_image.html

在运行上面的代码之前,我安装了 ghostscript 和这些包(按照说明):

install.packages("magick")
install.packages("webshot")
webshot::install_phantomjs()

当我按下 knit 时,我会收到以下消息:

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.

所以,我尝试使用 magick::image_read 手动读取 PDF 文件,这只会导致“R Session Aborted”(magick 中的类似功能:magick::image_read_pdf 工作得很好)。

我该如何解决这个问题?

【问题讨论】:

    标签: r-markdown docx kableextra


    【解决方案1】:

    当我跑步时

    ```{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")
    ```
    

    我得到了没有 kable 的单词,但我得到了 Rmarkdown 文件的文件名的 .PDF。尝试复制示例时遇到相同的错误,我想知道是否存在损坏的依赖项。你到底想做什么,特别是什么?

    【讨论】:

    • 我的目标是使用 kableExtra 表创建 docx 格式的输出。我需要与同事协作的特定格式...如果是损坏的依赖项,我该如何解决?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-29
    • 2019-02-01
    • 1970-01-01
    • 2021-12-30
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多