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

1

11

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.

Narra answered 12/9, 2012 at 20:6 Comment(4)
for the first error you saw, it seems that you are not ware of the concept working directory (type getwd() in R); the file myfile.Rmd must be under your current working directory; for the whole question, I hope StatET developers can pay attention to it; it really should not be too hard (see github.com/yihui/knitr/issues/252)Downdraft
Hi Yihui, thanks for your package. I was aware of getwd(), but not of the fact that I had to manually change the file type to .Rmd before running in with knitr. The other issue was that my wd could not have spaces (i.e. "working directory"Narra
(i.e. "\old projects\working directory") in the path. I hope this helps other users. Finally, I also hope StatET developers create a configuration to knit markdown in html.Narra
Just to clarify, you can have spaces in the directory.Downdraft
B
2

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.

Briolette answered 14/1, 2014 at 12:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.