Create a new document based on a template

Create (and optionally edit) a draft of an R Markdown document based on a template.

draft(file, template, package = NULL, create_dir = "default", edit = TRUE)
File name for the draft
Template to use as the basis for the draft. This is either the full path to a template directory or the name of a template directory within the rmarkdown/templates directory of a package.
(Optional) Name of package where the template is located.
TRUE to create a new directory for the document (the "default" setting leaves this beahvior up to the creator of the template).
TRUE to edit the template immediately

The draft function creates new R Markdown documents based on templates that are either located on the filesystem or within an R package. The template and it's supporting files will be copied to the location specified by file.


The file name of the new document (invisibly)


An R Markdown template consists of a directory that contains a description of the template, a skeleton Rmd file used as the basis for new documents, and optionally additional supporting files that are provided along with the skeleton (e.g. a logo graphic).

If the template directory is contained within a package then it should be located at inst/rmarkdown/templates. For example, a package named pubtools that wanted to provide a template named quarterly_report would need to provide the following files within the pubtools/inst/rmarkdown/templates directory:

quarterly_report/template.yaml quarterly_report/skeleton/skeleton.Rmd

The template.yaml file should include a name field. If you want to ensure that a new directory is always created for a given template, then you can add the create_dir field to the template.yaml file. For example:

create_dir: true

The skeleton/skeleton.Rmd file should include the initial contents you want for files created from this template. Additional files can be added to the skeleton directory, for example:


These files will automatically be copied to the directory containing the new R Markdown draft.

  • draft
## Not run: 
# rmarkdown::draft("Q4Report.Rmd",
#                  template="/opt/rmd/templates/quarterly_report")
# rmarkdown::draft("Q4Report.Rmd",
#                  template="quarterly_report", package="pubtools")
# ## End(Not run)
Documentation reproduced from package rmarkdown, version 1.0, License: GPL-3

Community examples

Looks like there are no examples yet.