我在VSCode中使用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的路径,因为我在VScode中输入了find_pandoc以找到版本和目录,显示了
> rmarkdown::find_pandoc()
$version
[1] '0'
$dir
NULL然而,在Rstudio中,它显示
> find_pandoc()
$version
[1] ‘2.7.2’
$dir
[1] "C:/Program Files/RStudio/bin/pandoc"发布于 2020-06-18 20:25:53
为了了解发生了什么,让我们看一下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中提取路径:
系统命令,它报告由shell执行的可执行文件(包括可执行脚本)的完整路径名.
尽管如此,您需要向系统上的PATH环境变量添加到pandoc的路径。
https://stackoverflow.com/questions/62409482
复制相似问题