I've been wanting to post about my experiences teaching using R and RStudioServer for teaching. I've got a list of big picture things, but today I'm thinking about a small, but for me crucial, one. 

In my classes and workshops I often use an rmarkdown template to help students get started.  You get the option to use a template when you create a new rmarkdown file.   Rmarkdown comes with two default templates one for a github document and one for a package vignette.  Both are wordy, but less so than the default markdown file, which my students find confusing at first and the annoying in always having to blank out.  

From the user point of view, a template is an RMarkdown file which contains some amount of predefined structure. I made that intentionally vauge because you can have a template that is a blank file if you want. But more often in my teaching I use templates to scaffold student work as they are learning to use R and RMarkdown.  Scaffolding is a term used in writing pedagogy.  Around Lehman most of the time it is used to me giving a students a  process of brainstorming, drafting, revision and polishing (and more depending on the course). It is also used to mean providing students with a structure for getting from point A to point B.  In my case point B is understanding specific concepts in statistics and R.

I use templates for both of these kinds of scaffolding when I teach with R.  For example, in the early exposure to R the experience can be very overwhelming for students. With a template I can structure experiences that are simple, but highly rewarding.  For example, they might just have to add a title to a graph, enter variable names into an analysis, and write some text.  For students who are further along, a template might provide the outline for a research report.  I also have a blank template that gets around the "first delete everything but the stuff at the top" step.

Creating a template is easy. It is just a markdown file. For example this is a somewhat complex file I created for a two-hour introduction to data science workshop this summer. The students had never used R before nor had most of them had any sociology, so I wanted to make a structure for the online part of the workshop that would ensure success.  This is the almost blank template file that I'm considering making even more blank. This is an outline for a project report.

You could, of course, just share these as gists, but I like to put them into a package so they can be opened directly from RStudio. To do that you can include them in an R package. Loading the package will add them to the list of options when creating a new file.  if you don't have a package you can use any of the package making tools to create a skeleton package.  

The templates rely on the somewhat magical inst folder in R packages.  That directory holds "installed files" which are basically all the other files you might need in your package.  They get copied to the top level when your package is installed using whatever file structure you have given them

These templates always require two files, and they go into  a subfolder in the inst/rmarkdown/templates folder.   So the blank template would be in inst/rmarkdown/templates/blank. At that level you add a file called template.yaml.  It is extremely important that you make sure there is an a in  the yaml file extension or RStudio willl not recognize that file when it scans for templates to list. Be careful because in saving and copying RStudio defaults to yml.  

The templates.yaml file should contain two items, name: and description.

name: blank
description: >
    A blank template

The other file should be called skeleton.Rmd  and placed in a subfolder called skeleton. 

The biggest problems I have with this system have to do with file extensions. If you have  yml instead of yaml or rmd instead of Rmd the templates may not show up on the list of templates.  The case issue is (from what I can tell) specific to Linux which is what most people probably have their instances of RStudioServer installed on.

Another small issue is  that different operating systems sort alphabetically differently, so not all students see the same list in the same order. 

Also I want to note that there is a whole different category of things called templates that are related to the templates package. It's not the only time that the same term is used in the context of unrelated things in R.

Updated to add information about the Rmd file extension.