R, knitr and Octopress
Recently, I moved this blog from tumblr to github since I feeled I need more liberty. I have no experience with web programming, so I chose Octopress as blogging framework since it nicely integrates with github.
However after relocation my workflow for generating posts was quite laborious - it was similar to the tumblr-workflow:
- Create an .Rmd file
- knit the file
- move the file to octopress/source/_posts/
- move the figures to octopress/source/figure/
- and so on…
This was non-satisfying and I thought that this must be automated into a smooth workflow!
Last week I took a look at the new Rcpp Gallery and noticed that this is also hosted on github. I skimmed through their code and found a lot of useful stuff. Shamelessly I copied some files from the and modified them for my octopress needs.
Basically I have now a folder for my .Rmd files (octopress/source/src). Invoking
make in this folder creates the markdown-files in _posts and sets up the right figure paths (in _posts/figure). My workflow now:
rake new_rmd[test], this sets up an empty .Rmd file in /src, according to the octopress naming-scheme and header.
- add my post to this .Rmd file
makein /src, this sets up the .markdown file in _posts and figures
- the usual
I am quite happy at the moment with this workflow. I can also use R-Studio.
Here are the changes I made to my octopress:
1) I added a new function
rake new_rmd to my Rakefile. This mimics the behavior of
and creates a .Rmd-file in source/src. Simply add these lines to your Rakefile:
2) I modified and cleaned
knit.sh from the Rcpp Gallery for my needs. This runs knitr on the .Rmd files and saves the output to _posts. Put this file (knit.sh) into source/_scripts!
3) Modified and cleaned the
Makefile from the Rcpp Gallery for my needs. This runs knit.sh on the /src folder, returns the .markdown files to _posts/ and cleans up the .md and .hmtl files created by R-Studio. Put this file (Makefile) into source/src!
You can skim through my github-repo for this site and copy the files from there. I have not tested this very extensively - in case you find any bugs or have improvements, please let me know.
I had to add this line of code
source/_includes/custom/head.html so that the figures are displayed properly, see