Sometimes, one document must be recreated in similar fashions a lot of times. For instance, invoices to customers, grading schemes for students, progress reports in projects, and so on. In this post, I demonstrate one way to do that in R using RMarkdown.
Specifically, it is assumed that there’s a tabular data set, where each row refers to a document instance (eg., a mail or report to one given person), and each column holds the variables to appear in each reports (see examples below). In addition, a template is provided where the variables are then parsed into. This template is built on latex, so that the output document is a pdf file.
Installation and usage
- Install R
- Install LaTeX
- Download/clone this repository
- Set the folder (of the downloaded material) as your working directory in R
- Run
render_rmd_mass_report()
inrender_rmd_mass_report.R
, it is assumed that all files are in the same folder.
Data file
grades.csv
is a toy data file for illustration purposes. It consists of two rows (two reports) with three variables.
Templates
grading_template.Rmd
This file is a simple RMarkdown file that holds the overall document.
latex-header.tex
This latex file holds the Latex backbone for the Rmarkdown template. Notice that dummy_logo.png
is read (and assumed to be in the same folder).
Adjusting
Feel free to adjust to your needs. In many cases it may suffice not to touch the latex file. If you change something, you need to make sure to change the variables in all sources:
- data file
- Rmd template
- render function
render_rmd_mass_report()
inrender_rmd_mass_report.R
Other stuff
render_example_images.R
is a helper file in order to render the examples images (from pdf to png).