Skip to contents

Create a new initializer function, and a spec file against which initialized templates can be checked.

Usage

init_template(name, files, dir = ".", spec_dir = ".", context = name,
  overwrite = FALSE)

Arguments

name

Name of the template to be checked.

files

List of paths to required files, relative to dir. "{name}" included in a path string will be replaced with name during checks. A list within the main list is treated as either alternatives files (when there is a single character vector), or alternative strict sets of files (must contain all of at least one list; when there are multiple character vectors).

dir

Package directory.

spec_dir

Parent directory of the files.

context

name of the template's context: itself, or another templated structure.

overwrite

logical; if TRUE, new files will replace existing ones.

Value

Creates a name.json file (in dir/inst/specs if it exists, or the current working directory), and invisibly returns its path.

Examples

if (FALSE) {

# creates a version of the function spec.
init_template("function", list("R/{name}.R", "tests/testthat/text-{name}.R"))

# creates a version of the shiny function, showing alternative sets
init_template("shiny", list(
  list(
    c("ui.R", "server.R"),
    "app.R"
  ),
  "README.md"
), spec_dir = "app")
}