\(~\)

What are RMarkdown Templates?

  • Preset formats for HTML, Word or PDF files produced with RMarkdown
  • Contained within an R package
    • A package may contain multiple templates (in separate sub-directories)
  • Accessed easily from RStudio “From Template” dialog box
    • File -> New File -> R Markdown

\(~\)

\(~\) \(~\)

Benefits

  • Maintain a standardized workflow
    • i.e., Checking whether all subject ids are unique or
    • Testing linear regression assumptions
  • Reduce human error resulting from copy-pasting code
  • Shift focus/time from formatting to the analysis

\(~\) \(~\)

Potential uses

  • As a Biostatistician
    • Save time on similar projects by using a template of commonly used code
    • AVOID copy-paste
    • Create your personal “brand” with custom report features
  • As an instructor or TA
    • Distribute your assignments/exams as templates to streamline grading
    • Share it on course repository

\(~\) \(~\)

How to create a template

\(~\)

Overview of the process

By creating a new package

  • Install devtools to help create a package
    • use devtools::create to create a name for your package (and produce the files and folders contained within)
    • use dir.create to create a special path to specify a template file
  • Create skeleton.Rmd
    • must be named skeleton.Rmd in the skeleton folder within your package
  • Create a template.yaml
  • Install your package

\(~\)

Adding a template to a package you have already created

  • Templates are located in the following directory of a package: inst/rmarkdown/templates
  • Generate this structure using the use_rmarkdown_template() function from the usethis package
  • Create a skeleton folder and your skeleton.rmd file plus the yaml file

\(~\)

Note:

  • Every time you make edits to your template (skeleton.rmd file), you’ll need to re-install your package
    • install.packages("/Users/gua2004/bigG/", repos=NULL, type="source")

Let’s look at an example

  • My basic consult report template contained in my package, bigG