RStudio + Blogdown + Github + Netlify = A winning formula

[This article was first published on R on R-house, 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.

I thought it was worth posting about how I set up this blog as I had enormous trouble setting it up. I’d never done anything like this before and so some Google searching exposed me to many different technologies, but I had no clue what they did, which were best/easiest to work with and which combination I needed to use them in.

First off, big thanks go to John Muschelli and his YouTube video which got me up and running in no time.

So if you want to go the route I have, you need several things installed on your machine:

  • R
  • RStudio
  • The blogdown package (obtained via the usual install.packages() function)
  • Hugo – you can install it from the blogdown package
  • Git

You will also need accounts with Github and Netlify.

John’s video explains how to go through the set-up process better than I can, but I do want to briefly explain my workflow (based on my limited understanding so far). To update my blog with a new post, these are the steps I take:

  1. I create a new markdown file for a new blog post, and save it in my r-house/content/post/ directory;
  2. I rebuild my site on my local machine with the command blogdown::build_site(). This sets off the website generation software Hugo which sits behind blogdown to create the required HTML pages in the r-house/public/ folder. The public folder holds all the files needed for the website.
  3. I register these changes with Git on my local machine, by staging and committing these changes from within RStudio (Tools>Version Control>Commit);
  4. I upload all of this to my GitHub repository by hitting the Push button.

That’s it! Once my GitHub repository updates, Netlify automatically refreshes my blog by recognising the public/ folder has changed.

My task now is to figure out how to use a different Hugo theme without breaking everything!

UPDATE 2018-01-03

After reading the blogdown documentation a bit more carefully, I’ve modified my workflow to let Netlify build my website for me. This required making the following changes:

  • Deleting the public/ folder and pushing the changes to GitHub;
  • Adding the public/ folder to the .gitignore file and pushing to GitHub;
  • Modifying my Netlify settings to build using the hugo build command (and setting a HUGO_VERSION environment variable);

I’ve now replaced step 2 with running a blogdown::serve_site() command so I can view a local version of my website and see updates happen as I make them. This automatically builds the necessary HTML pages for RMarkdown pages (as Hugo cannot do it itself).

Unfortunately, stopping the server crashes RStudio, so I have to run options(blogdown.generator.server = TRUE) before running it to stop it crashing when it’s stopped. Helpfully, I’ve found I can create a .Rprofile file in the website root directory containing this command so it loads automatically every time I load the project.

To leave a comment for the author, please follow the link and comment on their blog: R on R-house. 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)