File: use_template.Rd

package info (click to toggle)
r-cran-usethis 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,228 kB
  • sloc: sh: 26; makefile: 17; cpp: 6; ansic: 3
file content (63 lines) | stat: -rw-r--r-- 2,202 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/template.R
\name{use_template}
\alias{use_template}
\title{Use a usethis-style template}
\usage{
use_template(
  template,
  save_as = template,
  data = list(),
  ignore = FALSE,
  open = FALSE,
  package = "usethis"
)
}
\arguments{
\item{template}{Path to template file relative to \verb{templates/} directory
within \code{package}; see details.}

\item{save_as}{Path of file to create, relative to root of active project.
Defaults to \code{template}}

\item{data}{A list of data passed to the template.}

\item{ignore}{Should the newly created file be added to \code{.Rbuildignore}?}

\item{open}{Open the newly created file for editing? Happens in RStudio, if
applicable, or via \code{\link[utils:file.edit]{utils::file.edit()}} otherwise.}

\item{package}{Name of the package where the template is found.}
}
\value{
A logical vector indicating if file was modified.
}
\description{
Creates a file from data and a template found in a package. Provides control
over file name, the addition to \code{.Rbuildignore}, and opening the file for
inspection.
}
\details{
This function can be used as the engine for a templating function in other
packages. The \code{template} argument is used along with the \code{package} argument
to derive the path to your template file; it will be expected at
\code{fs::path_package(package = package, "templates", template)}. We use
\code{fs::path_package()} instead of \code{base::system.file()} so that path
construction works even in a development workflow, e.g., works with
\code{devtools::load_all()} or \code{pkgload::load_all()}. \emph{Note this describes the
behaviour of \code{fs::path_package()} in fs v1.2.7.9001 and higher.}

To interpolate your data into the template, supply a list using
the \code{data} argument. Internally, this function uses
\code{\link[whisker:whisker.render]{whisker::whisker.render()}} to combine your template file with your data.
}
\examples{
\dontrun{
  # Note: running this will write `NEWS.md` to your working directory
  use_template(
    template = "NEWS.md",
    data = list(Package = "acme", Version = "1.2.3"),
    package = "usethis"
  )
}
}