R Markdown1 is a powerful R package that allows users to dynamically render their work (code, graphs, and text) into various file formats. Its wide range of outputs (including HTML, PDF, Word) makes it one of the most flexible and intuitive communication tools within the R community. Ultimately, R Markdown bridges the gap between data professionals and the audience they need to communicate to. In fact, I’m communicating to you right now through an R Markdown document rendered to HTML.
In this blog post, I introduce my package,
hmdrmd, which extends
rmarkdown by providing document templates for data-oriented projects.
While using R Markdown default files, I found that I was consistently reformatting my documents into same general structure. Being an acolyte of tidy data2, I organized my data projects into the following sections:
- Communicate / Export
This diagram is particularly useful for organizing a data project into a logical workflow.
To avoid continuously reformatting every new R Markdown document to this structure, I created this template, called “Tidy Analysis”.
Example of Tidy Analysis PDF output
Case Study Analysis
The second R Markdown template in
hmdrmd is for case study analyses. This template is based on William Ellet’s case study guide in The Case Study Handbook, Revised Edition: A Student’s Guide4. This template is intended to be used by students in educational and research environments involving case analyses. This framework, in my opinion, is highly effective because it instructs students to pay attention to the most important issues and information in a case.
The document contains 12 essential steps, separated into 6 sections:
- Role and Scenario
- Action Plan
Example of Case Study Analysis PDF output
You can download the package using the following code:
if (!requireNamespace("devtools")) install.packages("devtools") devtools::install_github("HaydenMacDonald/hmdrmd")
In order to render pdf documents from R Markdown files, you will need LaTeX. If you have never installed a LaTex distribution, you can do so using the TinyTeX package.
tinytex are installed, you can access these templates in RStudio through the following path:
File > New File > R Markdown… > From Template.
Default settings for pdf output are controlled through the YAML header.
--- title: "title" author: "author" date: "2021-02-06" output: hmdrmd::case_study: highlight: tango mainfont: CMU Serif Roman monofont: Fira Code Medium ---
Remove or change these options from the YAML header to customize your document.
The default main font (
mainfont) and code font (
monofont) are set to CMU Serif Roman and Fira Code Medium, respectively. To use CMU Serif Roman and Fira Code Medium, follow their installation instructions. Additionally, you can change the syntax highlighting in code chunks through the highlight option in the YAML header. By default, it is set to
tango. Other options include
haddock. See this blog post by Garrick Aden-Buie for a gallery of these different options.
Submit issues on GitHub. Please feel free to extend this package by submitting a pull request!
Currently, these templates only render to PDF documents. If you are interested in extending the functionality of this package, fork the original repository, make your changes and submit them as a pull request.
1: Allaire, JJ., Xie, Y., McPherson, J., Luraschi J., Ushey, K., Atkins, A., Wickham, H., Cheng, J., Chang, W., & Iannone, R. (2017). rmarkdown: Dynamic documents for R. R package version 1.11. URL: https://CRAN.R-project.org/package=rmarkdown
4: Ellet, W. (2018). The case study handbook, revised edition: A student’s guide. Boston, Massachussets: Harvard Business Review Press.