Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to knitr and produce .rmd files using the external tools function of the StatET Eclipse plugin?

I'm becoming a fan of reproducible analyses and of Sweave, Beamer and specially of the knitr package.

RStudio allows to Sweave and knit documents with just one click, but although RStudio is easy to install, it is quite unstable and does not have the maturity and flexibility of the StatET plugin from Eclipse. Most tutorials or listservs tend to refer back to the RStudio IDE when asking questions about knitr and RMarkdown, but there's little out there about how to install and turn Markdown files into .Rmd using the knitr package. Jeffrey Horner said when he announced the R markdown package that:

"Markdown documents to HTML, created in collaboration with RStudio. It offers the complete R Markdown feature set available in their best-of-breed IDE, however useRs can integrate markdown into their own toolchain of choice."

The last sentence is what I have not been able to figure out. Elsewhere, I've seen suggested to manually knitr by using library(knitr); knit('myfile.Rmd'), however, when attempting to do this, I receive an error:

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

I was able to turn the My file.md file into html using:

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

However, the R code is not run, and I suspect that I need to knit the .Rmd file first. Any help or directions about how to be able to knitr markdown files in StatET or somewhere else than Rstudio would be much appreciated.

I'm using R version 2.15.1 (2012-06-22) on a Windows 7 Professional OS. Eclipse Version: 3.8.0 and StatET 3.0.

like image 822
rogervv Avatar asked Sep 12 '12 20:09

rogervv


1 Answers

One way to do it is to use an R snippet:

1) create a stateET R project, with this file https://raw.github.com/yihui/knitr-examples/master/001-minimal.Rmd in it.

2) in Windows-> Preferences -> StatET -> Run/Debug -> R Code Snippets

click "Add...". to create a new snipped called Rmd2html. content of the snippet:

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)

click "OK", "OK".

3) back in your project, in the Project Explorer view, right click on the minimal.Rmd file, and select "Run Code Snippet in R -> Rmd2html"

This should generate the minimal.html file.

like image 164
Karl Forner Avatar answered Sep 27 '22 02:09

Karl Forner