1

How to integrate R code in markdown and then insert the plots in the rendered document?

I use the blogging engine Hakyll (http://jaspervdj.be/hakyll/). It uses Pandoc as a back-end for rendering blog posts written in markdown.

cdupont
  • 1,138
  • 10
  • 17

3 Answers3

1

There's even a special markdown flavor named R-markdown. It can be rendered to plain markdown using the knitr package.

Apparently the link provided directs to a page about R-markdown V2 which has its own package rmarkdown.

ziggystar
  • 28,410
  • 9
  • 72
  • 124
  • I know about R-markdown, but how to render it in Hakyll? If I understand it's a preprocessor of plain markdown? Can it be plugged to Pandoc? – cdupont Dec 09 '14 at 12:49
  • @cdupont You will have to use R at one point or the other to create the plots. Why not use R-markdown as it is intended? Judging from the main-page of Hakyll you can simply create a new compile rule to run `*.Rmd` files through R. before feeding the result to pandoc. – ziggystar Dec 09 '14 at 13:13
  • @ziggystart Great, I'll try that! If that works I 'll post the code. – cdupont Dec 09 '14 at 14:01
  • @cdupont I don't understand your edit. You don't `require` `rmarkdown` for using the `knit` command. It provides the `rmarkdown::render` function, why do you load both packages when using only `knit`? – ziggystar Dec 15 '14 at 20:58
  • @ziggystart: OK, I didn't know. I wanted to add a method for use with Hakyll. – cdupont Dec 16 '14 at 23:19
1

FYI I published a package that allows to compile Rmd posts in Hakyll: https://hackage.haskell.org/package/hakyll-R

cdupont
  • 1,138
  • 10
  • 17
0

For the moment I write my blog post in Rmarkdown, and transform it in plain markdown with:

Rscript -e "library(knitr); knit('myPost.Rmd')

Then Hakyll can process it. More details here: http://www.corentindupont.info/blog/posts/Programming/2014-12-10-This-Blog.html. I would be glad to know if this command can be integrated directly into Hakyll.

cdupont
  • 1,138
  • 10
  • 17