/
rmarkdown.R
51 lines (47 loc) 路 1.76 KB
/
rmarkdown.R
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
#' Add an RMarkdown Template
#'
#' Adds files and directories necessary to add a custom rmarkdown template to
#' RStudio. It creates:
#' * `inst/rmarkdown/templates/{{template_dir}}`. Main directory.
#' * `skeleton/skeleton.Rmd`. Your template Rmd file.
#' * `template.yml` with basic information filled in.
#'
#' @param template_name The name as printed in the template menu.
#' @param template_dir Name of the directory the template will live in within
#' `inst/rmarkdown/templates`. If none is provided by the user, it will be
#' created from `template_name`.
#' @param template_description Sets the value of `description` in
#' `template.yml`.
#' @param template_create_dir Sets the value of `create_dir` in `template.yml`.
#'
#' @export
#' @examples
#' \dontrun{
#' use_rmarkdown_template()
#' }
use_rmarkdown_template <- function(template_name = "Template Name",
template_dir = NULL,
template_description = "A description of the template",
template_create_dir = FALSE) {
# Process some of the inputs
template_dir <- template_dir %||% tolower(asciify(template_name))
template_create_dir <- as.character(template_create_dir)
template_dir <- path("inst", "rmarkdown", "templates", template_dir)
# Scaffold files
use_directory(path(template_dir, "skeleton"))
use_template(
"rmarkdown-template.yml",
data = list(
template_dir = template_dir,
template_name = template_name,
template_description = template_description,
template_create_dir = template_create_dir
),
save_as = path(template_dir, "template.yaml")
)
use_template(
"rmarkdown-template.Rmd",
path(template_dir, "skeleton", "skeleton.Rmd")
)
invisible(TRUE)
}