| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/draft.R |
| 3 |
\name{draft} |
| 4 |
\alias{draft} |
| 5 |
\title{Create a new document based on a template} |
| 6 |
\usage{ |
| 7 |
draft(file, template, package = NULL, create_dir = "default", edit = TRUE) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{file}{File name for the draft} |
| 11 |
|
| 12 |
\item{template}{Template to use as the basis for the draft. This is either |
| 13 |
the full path to a template directory or the name of a template directory |
| 14 |
within the \code{rmarkdown/templates} directory of a package.} |
| 15 |
|
| 16 |
\item{package}{(Optional) Name of package where the template is located.} |
| 17 |
|
| 18 |
\item{create_dir}{\code{TRUE} to create a new directory for the document |
| 19 |
(the "default" setting leaves this behavior up to the creator of the |
| 20 |
template).} |
| 21 |
|
| 22 |
\item{edit}{\code{TRUE} to edit the template immediately} |
| 23 |
} |
| 24 |
\value{ |
| 25 |
The file name of the new document (invisibly). |
| 26 |
} |
| 27 |
\description{ |
| 28 |
Create (and optionally edit) a draft of an R Markdown document based on a |
| 29 |
template. |
| 30 |
} |
| 31 |
\details{ |
| 32 |
The \code{draft} function creates new R Markdown documents based on |
| 33 |
templates that are either located on the filesystem or within an R package. |
| 34 |
The template and its supporting files will be copied to the location |
| 35 |
specified by \code{file}. |
| 36 |
} |
| 37 |
\note{ |
| 38 |
An R Markdown template consists of a directory that contains a |
| 39 |
description of the template, a skeleton Rmd file used as the basis for new |
| 40 |
documents, and optionally additional supporting files that are provided |
| 41 |
along with the skeleton (e.g. a logo graphic). |
| 42 |
|
| 43 |
If the template directory is contained within a package then it should be |
| 44 |
located at \code{inst/rmarkdown/templates}. For example, a package named |
| 45 |
\pkg{pubtools} that wanted to provide a template named |
| 46 |
\code{quarterly_report} would need to provide the following files within |
| 47 |
the \code{pubtools/inst/rmarkdown/templates} directory: |
| 48 |
|
| 49 |
\code{quarterly_report/template.yaml} \cr |
| 50 |
\code{quarterly_report/skeleton/skeleton.Rmd} \cr |
| 51 |
|
| 52 |
The \code{template.yaml} file should include a \code{name} field. If you |
| 53 |
want to ensure that a new directory is always created for a given template, |
| 54 |
then you can add the \code{create_dir} field to the \code{template.yaml} |
| 55 |
file. For example: |
| 56 |
|
| 57 |
\code{create_dir: true} \cr |
| 58 |
|
| 59 |
The \code{skeleton/skeleton.Rmd} file should include the initial contents |
| 60 |
you want for files created from this template. Additional files can be |
| 61 |
added to the \code{skeleton} directory, for example: |
| 62 |
|
| 63 |
\code{skeleton/logo.png} \cr |
| 64 |
|
| 65 |
These files will automatically be copied to the directory containing the |
| 66 |
new R Markdown draft. |
| 67 |
} |
| 68 |
\examples{ |
| 69 |
\dontrun{ |
| 70 |
rmarkdown::draft("Q4Report.Rmd", |
| 71 |
template="/opt/rmd/templates/quarterly_report") |
| 72 |
|
| 73 |
rmarkdown::draft("Q4Report.Rmd", |
| 74 |
template="quarterly_report", package="pubtools") |
| 75 |
} |
| 76 |
} |