11 Including templates

We now add the .Rmd templates to the package. We have the skeleton.Rmd defined in source-files. Note that paths are relative to the outputted package’s location.

The first template is the simplest imaginable package with a single function:

usethis::use_rmarkdown_template(
  template_name = "Template To Make an R Package",
  template_dir = "make-an-r-package",
  template_description = "Template for an Rmd file for writing an R package using literate programming.",
  template_create_dir = FALSE
)
fs::file_copy(
  path = file.path(
    "..", "source-files", "make-an-r-package", "skeleton.Rmd"
    ), 
  new_path = file.path(
    "inst", "rmarkdown", "templates", "make-an-r-package", "skeleton"
    ), 
  overwrite = TRUE
)
## ✔ Creating 'inst/rmarkdown/templates/make-an-r-package/skeleton/'
## ✔ Writing 'inst/rmarkdown/templates/make-an-r-package/template.yaml'
## ✔ Writing 'inst/rmarkdown/templates/make-an-r-package/skeleton/skeleton.Rmd'

The second template shows how to create a package with a dataset:

usethis::use_rmarkdown_template(
  template_name = "Template To Make an R Package With a Dataset",
  template_dir = "make-an-r-package-with-data",
  template_description = "Template for an Rmd file for writing an R package with a dataset using literate programming.",
  template_create_dir = FALSE
)
fs::file_copy(
  path = file.path(
    "..", "source-files", "make-an-r-package-with-data", "skeleton.Rmd"
    ), 
  new_path = file.path(
    "inst", "rmarkdown", "templates", "make-an-r-package-with-data", "skeleton"
    ), 
  overwrite = TRUE
)
## ✔ Creating 'inst/rmarkdown/templates/make-an-r-package-with-data/skeleton/'
## ✔ Writing 'inst/rmarkdown/templates/make-an-r-package-with-data/template.yaml'
## ✔ Writing 'inst/rmarkdown/templates/make-an-r-package-with-data/skeleton/skeleton.Rmd'

The third template shows how to create a package that uses Rcpp:

usethis::use_rmarkdown_template(
  template_name = "Template To Make an R Package With Rcpp",
  template_dir = "make-an-r-package-with-rcpp",
  template_description = "Template for an Rmd file for writing an R package that makes use of Rcpp while using literate programming.",
  template_create_dir = FALSE
)
fs::file_copy(
  path = file.path(
    "..", "source-files", "make-an-r-package-with-rcpp", "skeleton.Rmd"
    ),
  new_path = file.path(
    "inst", "rmarkdown", "templates", "make-an-r-package-with-rcpp", "skeleton"
    ),
  overwrite = TRUE
)
## ✔ Creating 'inst/rmarkdown/templates/make-an-r-package-with-rcpp/skeleton/'
## ✔ Writing 'inst/rmarkdown/templates/make-an-r-package-with-rcpp/template.yaml'
## ✔ Writing 'inst/rmarkdown/templates/make-an-r-package-with-rcpp/skeleton/skeleton.Rmd'

The fourth template shows how to create a package with “extras” such as a README, a vignette, and a pkgdown site:

usethis::use_rmarkdown_template(
  template_name = "Template To Make an R Package With a README, Vignette, and Pkgdown Site",
  template_dir = "make-an-r-package-with-extras",
  template_description = "Template for an Rmd file for writing an R package that has a README, vignette, and pkgdown site while using literate programming.",
  template_create_dir = FALSE
)
fs::file_copy(
  path = file.path(
    "..", "source-files", "make-an-r-package-with-extras", "skeleton.Rmd"
    ),
  new_path = file.path(
    "inst", "rmarkdown", "templates", "make-an-r-package-with-extras", "skeleton"
    ),
  overwrite = TRUE
)
fs::dir_copy(
  path = file.path(
    "..", "source-files", "make-an-r-package-with-extras", "source-files"
    ),
  new_path = file.path(
    "inst", "rmarkdown", "templates", "make-an-r-package-with-extras", "skeleton",
    "source-files"
    ),
  overwrite = TRUE
)
## ✔ Creating 'inst/rmarkdown/templates/make-an-r-package-with-extras/skeleton/'
## ✔ Writing 'inst/rmarkdown/templates/make-an-r-package-with-extras/template.yaml'
## ✔ Writing 'inst/rmarkdown/templates/make-an-r-package-with-extras/skeleton/skeleton.Rmd'

The fifth template shows how to create a package from a bookdown site, i.e. instead of having just a single create-pkg.Rmd, we can have a series of .Rmd files that together create a bookdown:

usethis::use_rmarkdown_template(
  template_name = "Template To Make an R Package From a Bookdown",
  template_dir = "make-an-r-package-from-bookdown",
  template_description = "Template for a bookdown that defines an R package using literate programming.",
  template_create_dir = TRUE
)
fs::dir_copy(
  path = file.path("..", "source-files", "make-an-r-package-from-bookdown"),
  new_path = file.path(
    "inst", "rmarkdown", "templates", "make-an-r-package-from-bookdown", "skeleton"
    ),
  overwrite = TRUE
)
## ✔ Creating 'inst/rmarkdown/templates/make-an-r-package-from-bookdown/skeleton/'
## ✔ Writing 'inst/rmarkdown/templates/make-an-r-package-from-bookdown/template.yaml'
## ✔ Writing 'inst/rmarkdown/templates/make-an-r-package-from-bookdown/skeleton/skeleton.Rmd'

The sixth template shows how to create a package that uses RcppArmadillo:

usethis::use_rmarkdown_template(
  template_name = "Template To Make an R Package With RcppArmadillo",
  template_dir = "make-an-r-package-with-armadillo",
  template_description = "Template for an Rmd file for writing an R package that makes use of RcppArmadillo while using literate programming.",
  template_create_dir = FALSE
)
fs::file_copy(
  path = file.path(
    "..", "source-files", "make-an-r-package-with-armadillo", "skeleton.Rmd"
    ),
  new_path = file.path(
    "inst", "rmarkdown", "templates", "make-an-r-package-with-armadillo", "skeleton"
    ),
  overwrite = TRUE
)
## ✔ Creating 'inst/rmarkdown/templates/make-an-r-package-with-armadillo/skeleton/'
## ✔ Writing 'inst/rmarkdown/templates/make-an-r-package-with-armadillo/template.yaml'
## ✔ Writing 'inst/rmarkdown/templates/make-an-r-package-with-armadillo/skeleton/skeleton.Rmd'