Making Jekyll Blog Suitable for R-bloggers

[This article was first published on Yongfu's Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

According to the post add your blog, adding one’s blog to R-bloggers isn’t easy at all, especially for people who use R Markdown to write posts and use Jekyll to generate static web page on GitHub.

Two reasons make it difficult:

  1. The feed you submit should ONLY be about R (e.g: with R code, or directly related to the R world/community).

    • This causes problem because most bloggers write posts spanning several topics, and some blogging platform doesn’t support RSS feed for a particular category of posts.
  2. Make sure the HTML of your feed’s content is well formatted – otherwise it would not be able to load on r-bloggers. This includes to NOT copy-pasting from RStudio’s notebook extension – the feed should NOT include “base64” images, make sure your images are saved as png or similar file formats.

    • For posts written with R Markdown and HTML Fragment output format, the embedded images generated from code chunks (such as outputs from plot()) are base64 images.

Fixing the First Problem

For Jekyll sites using jekyll-feed plugin to generate sitemaps, it is not possible to have RSS feed for a particular tag or category of posts. However there’s a workaround using Jekyll’s Liquid syntax to write an RSS template, as indicated by this post. I modified the template to make it suitable for the criteria set by R-bloggers, you can take a look at the file feed.rbloggers.xml.

Fixing the Second Problem

To fix the second problem, set self_contained: false in the yaml header of the R Markdown document. With this setting, plots from code chunks are automatically generated in a figure directory, and the .html output uses tags to source the plots in that figure directory.

    self_contained: false

However, this creates a problem since the relative path in the tags probably won’t work in the remote directory that hosts your site. To overcome this problem, you have to change the default figure directory and post-process the output .html file.

For example, the source of this post(rblogger-criteria.rmd) is two layers under the root dir of the web site.

|   +---rblogger-criteria-img/
|   +---rblogger-criteria/
|   |   +---rblogger-criteria.rmd
|   |   +---rblogger-criteria.html

I set my figure directory to assets/rblogger-criteria-img/:

```{r setup, include=FALSE}
    fig.path = "../../assets/rblogger-criteria-img/"

so when the site is rendered, the image would be in

The last thing to do is processing the output rblogger-criteria.html and replacing in the tag. I do this with a simple bash script:

sed "s# temp
cat temp > rblogger-criteria.html

A Demo

Below is a plot generated from an R Markdown code chunk, you can look at the path in tag with the developer’s tool or the image source to confirm the path of the image is just as mentioned above.

ggplot(iris, aes(Sepal.Length, Petal.Width)) +
    geom_point(aes(color = Species))

Visit R-bloggers
Last updated: 2018-08-02

To leave a comment for the author, please follow the link and comment on their blog: Yongfu's Blog. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)