Alternate R Markdown Templates

February 4, 2016

(This article was first published on R –, and kindly contributed to R-bloggers)

The knitr/R markdown system is a great way to organize reports and analyses. However, the built-in ones (that come with RStudio/the rmarkdown package) rely on Bootstrap and also use jQuery. There’s nothing wrong with that, but the generated standalone HTML documents (which are a great way to distribute reports) don’t really need all that cruft and it’s fun & informative to check out new frameworks from time-to-time. Also, jQuery is a heavy crutch I’m working hard to not need anymore.

To that end, I created a package — markdowntemplates — that contains three alternate templates that you can use out of the box or (hopefully) clone, customize and use in your future work. One template is based on the Bulma CSS framework, the other is based on the Skeleton CSS framework and the last one is a super-minimal template with no formatting (i.e. it’s a good one to build on).

The github repo has screenshots of the basic formatting.

I tried to keep with the base formatting of each theme, but I went a bit crazy and showed how to have a fixed banner in the Skeleton version.

How it works

There are three directories inside inst/rmarkdown/templates each has a similar structure:

  • a resources directory with CSS (and potentially javascript)
  • a skeleton directory which holds example Rmd “skeleton” files
  • a base.html file which is the parameterized HTML template for the Rmd
  • a template.yaml file which is how RStudio/knitr knows there’s one or more R markdown templates in your package

The minimal base.html is small enough to include here:










  $for(include-before)$ $include-before$ $endfor$   $if(toc)$
$endif$   $body$   $for(include-after)$ $include-after$ $endfor$  
  $if(mathjax-url)$ $endif$  

I kept a bit of the RStudio template code for source code formatting, but grokking the actual template language should be pretty straightforward. You should be able to pick out $title$ in there and you can add as many parameters to the Rmd YAML section as you like (with corresponding counterparts in that template). I added a corresponding, exported R function for each supported template to show how easy it is to customize the parameters while also accepting further customizations in the YAML of each Rmd.

Imagine building a base template with your personal or organization’s branding and having it set apart from the cookie-cutter RStudio rmarkdown Bootstrap/jQuery template. Or, create course-specific templates like the s20x package. Once you peek behind the curtain to see how things are done, it’s not so complex and the sky is the limit.

I’ll try to get these in CRAN as soon as possible. If you have a preference for another CSS framework (I’m thinking of adding a “Metro” CSS kit and a Google web starter CSS kit), shoot me an issue or PR and I’ll incorporate it. The more examples we have the easier it will be for folks to create new templates.

Any & all feedback is most welcome.

To leave a comment for the author, please follow the link and comment on their blog: R – offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


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)