r - 如何解决 pandoc 问题

标签 r vscode-settings pandoc

使用saveWidget时遇到问题在 VSCode 中,这可能是由 pandoc 引起的.

当我在 Rstudio 中运行以下行时,它运行良好且 mtcars.html可以生成

htmlwidgets::saveWidget(DT::datatable(mtcars), "mtcars.html", selfcontained = TRUE, title = "mtcars")

但是,当我将相同的代码移动到 VSCode 时,它​​给了我一个错误,说
Error in htmlwidgets::saveWidget(DT::datatable(mtcars), "mtcars.html",  : 
  Saving a widget with selfcontained = TRUE requires pandoc. For details see:
https://github.com/rstudio/rmarkdown/blob/master/PANDOC.md

我怀疑 VSCode 无法识别 pandoc 的路径, 因为我输入了 find_pandoc在VScode中找到版本和目录,显示
> rmarkdown::find_pandoc()
$version
[1] '0'

$dir
NULL

但是,在 Rstudio 中它显示
> find_pandoc()
$version
[1] ‘2.7.2’

$dir
[1] "C:/Program Files/RStudio/bin/pandoc"

最佳答案

为了了解是怎么回事,我们先来看看rmarkdown:::find_pandoc()的源代码.我们可以在那里找到以下几行:

sys_pandoc <- find_program("pandoc")
sources <- c(Sys.getenv("RSTUDIO_PANDOC"), if (nzchar(sys_pandoc)) dirname(sys_pandoc))
sources然后用于获取 pandoc小路。我怀疑在你的情况下 RSTUDIO_PANDOC未设置,所以 rmarkdown:::find_pandoc()依赖 find_program("pandoc")找到路径。反过来看它的源码,你会发现路径是通过运行Sys.which来确定的。 ,相当于从shell中提取路径:

The system command which reports on the full path names of an executable (including an executable script) as would be executed by a shell...



话虽如此,您需要将 pandoc 的路径添加到 PATH系统上的环境变量。

关于r - 如何解决 pandoc 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62409482/

相关文章:

visual-studio-code - VS Code 智能感知的方式

pandoc - pandoc 中的智能引号和连字

haskell - 使用pandoc作为库制作PDF

r - 如何在 R 中将两个每周日期相减?

不要进入 vscode 工作区设置用户设置

visual-studio-code - Visual Studio Code 中每个工作区的 keybindings.json

haskell - 使用 CSS 或模板自定义 Pandoc 的 HTML 输出

r - 按两列中的值范围匹配数据框中的行

api - 应用getForm时偶尔会得到 "attempt to apply non-function"错误

r - 如何在R中堆叠数据?