After getting my blog started using Jekyll1, I started to wonder how to setup a process to go seamlessly from R markdown to blog post. I came across the knitr-jekyll2 project, which had a similar purpose. The suggested process from knitr-jekyll project is detailed here.
I had slighly different requirements, so I had to make a few modifications. Some of these issues and their solutions are discussed by others3 before.
First of all, I prefer to generate the first round of html (or other outputs) using the default format of R markdown and check the results in RStudio. Secondly, I would prefer the original markdown files to reside inside their respective projects.
Below is what I could come up with:
One-time steps
- Copy Build.R file from knitr-jekyll project to my github.io project.
- Create _source directory in the github.io project.
- The syntax highlighting was not working as I’d like to out-of-the-box. My Jekyll setup uses Rouge as the syntax highlighter and Rouge is compatible with Pygments stylesheets. So, one can pick her favorite style from richleland’s pygment-css project, download it to your css folder and add it to the pages. One more thing, these css files are designed with
codehilite
tag, which should be replaced by your css style for highlight,highlight
in my case.
Regular Steps
- Copy finalized Rmd file from the original project to _source directory.
- Make sure you are using Jekyll’s file naming conventions.
- Front Matter (The header of the markdown file) modifications:
- Remove
output
tag - Change data format to appropriate format (YYYY-MM-DD, in my case)
- Add
layout
tag - Add
categories
,tags
, etc. if you like
- Remove
- Run
servr::jekyll()
command. I know it’s sometimes tricky to get it to work. - The last step builds an .md file from your .Rmd and puts it in the _posts directory.
- Check if the new post works locally. (Stop your RStudio Jekyll process, if needed and run your local Jekyll to test)
- Commit and push to Github.io if everything looks OK.
References
-
knitr-jekyll, a project by @yihui ↩