Including “worksheets” or report templates with R Markdown
An .Rmd template is essentially the replacement for a worksheet. It is a partially-filled out R Markdown file that you can create. You can create a template for every homework assignment or exercise that you want your students to work through. And they can access all of these templates easily when they go to
New File >
R Markdown. And then select
From Template from the dialogue box menu. Your custom R Markdown template will appear there.
You can make a couple templates for general use cases (e.g. “Homework”, “Reports”, “Final Project”) or you can make as many very specific templates populated with questions or tailored excercies (e.g. “Lesson 1 Excerices”, “Problem Set 2”).
As a rough outline, to make your first template you will:
- Use a usethis function
use_rmarkdown_template()to create the necessary directory and file structure within your package.
- Modify the template.
- Save, Build, Install, and Restart.
If you’re unfamiliar with the basics of RMarkdown and need to learn the syntax, then first you will want to check-out the resources and tutorials we’ve compiled here.
I assume you have already created the basic package infrastructure from Part 1.
use_rmarkdown_template(template_name = "<your-template-name")
use_rmarkdown_template(template_name = "Worksheet1") '/Users/desiree/Documents/New R Projects/testpackage' ✔ Setting active project to 'inst/rmarkdown/templates/worksheet1/skeleton/' ✔ Creating 'inst/rmarkdown/templates/worksheet1/template.yaml' ✔ Writing 'inst/rmarkdown/templates/worksheet1/skeleton/skeleton.Rmd' ✔ Writing >
This creates a new folder in the root package directory
inst/ with several subdirectories.
inst/rmarkdown/templates/<your-template-name>/skeleton/. This is what you’re users will see. consider what you’d like the output format to be.
- To see some examples of how here.
- You can also include a description of your template in the
template.yamlfile in the parent directory
skeleton/. But this is not critical to getting the template into the package.
- Save, Build > Install and Restart
You can get ideas for how minimal
.Rmd templates can be customized by checkout out a few example templates here.
- Once your R session has been restarted, navigate to
R Markdown. Select
From Templatefrom the dialogue box menu. Your custom R Markdown template will appear there. Voilà!
Tip: You can continue to add new .Rmd templates to your package throughout your course. When you do, ask students to update the package, and they will access to the new templates.
[INSERT DAVID MEZA QUOTE]
We next show you how you can introduce a special type of .Rmd document in your package: a LearnR tutorial.