R versions >= 3.2.2 等同于 "Run Document" 的命令行,以便 markdown 文件可以访问全局环境

Command line equivalent to "Run Document" for R versions >= 3.2.2 so that markdown files can access the global environment

我正在制作交互式 R Markdown 报告,Shiny 提供交互性。我遇到一个问题,当我在 RStudio 中单击 "Run Document" 时无法访问全局环境中的变量(如所述 here). That same sections describes how you can use rmarkdown::run(...) to run the document from the command line, and 表明这允许报告访问全局环境中的变量。

但是,对于我的 R 版本,我在弹出窗口中收到以下错误 window:

Error: pandoc version 1.12.3 or higher is required and was not found.

当我尝试安装 pandoc 时,我得到:

> install.packages("pandoc")
Warning in install.packages :
  package ‘pandoc’ is not available (for R version 3.2.2)

有解决办法吗?

pandoc 不是 R 包。这是您需要在系统上安装的东西。如果您没有安装,RStudio 会提供它。如果您不想手动安装 pandoc,更新 RStudio 应该可以解决这个问题。