Search code examples
rgitr-markdowngithub-pagesbookdown

Serve RMarkdown outputs without version controlling them


We frequently use RMarkdown based packages to create websites with R (bookdown, blogdown, distill...) and use github-pages to serve the html files via the url username.github.io/repo.

In this approach, the ouput (i.e. html / css) files are also version controlled, and are frequently included in commits by mistake (git commit -a). This is annoying since these files clutter the commit and often lead to fictitious files conflicts.

Ideally, the outputfiles would not be version controlled at all, since the binary files (images) additionally bloat the repo. So I'm looking for a solution where:

  • Git ignores the output files completely but provides an alternative (but comparable1) method to gh-pages to serve them
  • Git ignores the output files temporally and committing / pushing them to gh-pages is done in a separate, explicit command

1: The method should be command line based and provide a nice URL to access the website


Solution

  • If you have a python installation on your computer, you can use GitHub Pages Import, a tool designed specifically for this purpose.

    You need a python installation since it has to be installed with pip, but once it's installed it integrates beautifully with into an R / RMarkdown workflow.

    Once it's installed (pip install ghp-import), you can run ghp-import docs (assuming docs is where your RMarkdown outputs are stored).

    There are a bunch of practical options that you can use, including -p to additionally push the changes to your remote after the commit.