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:
skeletondirectory which holds example
base.htmlfile which is the parameterized HTML template for the Rmd
template.yamlfile which is how RStudio/
knitrknows there’s one or more R markdown templates in your package
base.html is small enough to include here:
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
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.