【问题标题】:Is there a way to knitr and produce .rmd files using the external tools function of the StatET Eclipse plugin?有没有办法使用 StatET Eclipse 插件的外部工具功能来编织和生成 .rmd 文件?
【发布时间】:2012-09-05 21:44:13
【问题描述】:

我正在成为可重复分析和 Sweave、Beamer 以及特别是 knitr 包的粉丝。

RStudio允许一键Sweave和编织文档,但是RStudio虽然易于安装,但相当不稳定,不具备Eclipse StatET插件的成熟度和灵活性。大多数教程或列表服务器在询问有关 knitr 和 RMarkdown 的问题时倾向于参考 RStudio IDE,但是关于如何使用 knitr 包安装 Markdown 文件并将其转换为 .Rmd 的内容很少。 Jeffrey Horner 在宣布 R 降价包时说:

“与 RStudio 合作创建的将 Markdown 文档转换为 HTML。它在其同类最佳的 IDE 中提供了完整的 R Markdown 功能集,但用户可以将 Markdown 集成到他们自己选择的工具链中。”

最后一句是我一直想不通的。在其他地方,我看到有人建议使用 library(knitr); knit('myfile.Rmd') 手动 knitr,但是,在尝试执行此操作时,我收到一个错误:

Warning in file(con, "r") :
  cannot open file 'My file.Rmd': No such file or directory
Error in file(con, "r") : cannot open the connection

我能够使用以下方法将My file.md 文件转换为 html:

library(markdown)
markdownToHTML(file = "C:/Dropbox/eclipse/8. CM/Myfile", output="C:/Dropbox/eclipse/8. CM/Myfile.html")

但是,R 代码没有运行,我怀疑我需要先编织.Rmd 文件。任何有关如何在 StatET 或 Rstudio 以外的地方编写 markdown 文件的帮助或指导将不胜感激。

我在 Windows 7 Professional 操作系统上使用 R 版本 2.15.1 (2012-06-22)。 Eclipse 版本:3.8.0 和 StatET 3.0。

【问题讨论】:

  • 对于您看到的第一个错误,您似乎没有意识到 working directory 的概念(在 R 中键入 getwd());文件myfile.Rmd 必须在您当前的工作目录下;对于整个问题,希望StatET开发者能够重视;真的不应该太难(见github.com/yihui/knitr/issues/252
  • 您好,一辉,感谢您的包裹。我知道 getwd(),但不知道在使用 knitr 运行之前我必须手动将文件类型更改为 .Rmd。另一个问题是我的 wd 不能有空格(即“工作目录”
  • (即“\old projects\working directory”)在路径中。我希望这可以帮助其他用户。最后,我也希望 StatET 开发者创建一个配置来在 html 中编织 markdown。
  • 澄清一下,目录中可以有空格。

标签: r knitr literate-programming statet r-markdown


【解决方案1】:

一种方法是使用 R sn-p

1) 创建一个 stateET R 项目,其中包含此文件 https://raw.github.com/yihui/knitr-examples/master/001-minimal.Rmd

2) 在 Windows-> 首选项 -> StatET -> 运行/调试 -> R 代码片段

单击“添加...”。创建一个名为 Rmd2html 的新片段。 sn-p的内容:

file <- "${selected_resource_loc}"
if (!nzchar) stop('Select a file first')
library(knitr)
library(markdown)
library(tools)
md_file <- knit(file)
html_file <- paste(file_path_sans_ext(md_file), '.html', sep = '')
markdownToHTML(md_file, html_file)

点击“确定”、“确定”。

3) 回到您的项目,在 Project Explorer 视图中,右键单击 minimal.Rmd 文件, 并选择“在 R -> Rmd2html 中运行代码片段”

这应该会生成 minimum.html 文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-12
    • 1970-01-01
    • 2015-05-26
    • 2014-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-02
    相关资源
    最近更新 更多