Creates a new Quarto document in the specified directory, along with a sample dataset and UW-Madison branded assets. Optionally pre-populates the YAML header with user-supplied metadata.
Usage
create_qmd(
filename = NULL,
path = ".",
yaml_data = NULL,
overwrite = FALSE,
use_purl = TRUE
)Arguments
- filename
A string or
NULL. Name of the generated.qmdfile. Must be supplied explicitly, e.g."analysis.qmd".- path
A string. Path to the directory where the document will be created. Defaults to
"."(the current working directory).- yaml_data
A string or
NULL. Path to a YAML file containing metadata to pre-populate the document header. IfNULL(the default), the template is copied as-is with placeholder prompts intact.- overwrite
A logical. Whether to overwrite existing files. Defaults to
FALSE.- use_purl
Logical. If
TRUE(the default), creates a_quarto.ymlfile with a post-render hook and apurl.Rscript insideR/that extracts R code from the rendered document into a.Rfile. The target document is resolved dynamically by scanning the project root for.qmdfiles, so the samepurl.Rworks regardless of the document name.
Details
create_qmd() performs the following steps:
Validates that
pathexists.Validates that
filenameis supplied.Creates a
data/folder underpathand copiessample.csvthere.Checks for
assets/styles.cssandassets/header.html- creates theassets/folder if needed and copies both from the package.Copies the template
.qmdtopath/filename.If
yaml_datais provided, reads the YAML file and substitutes values into the document header.If
use_purl = TRUE, writes a_quarto.ymlwith a post-render hook pointing toR/purl.R, and copiespurl.Rfrom the package templates intopath/R/purl.R.The sample dataset bundled with the template is a subset of the Palmer Penguins dataset. Citation: Horst AM, Hill AP, Gorman KB (2020). palmerpenguins: Palmer Archipelago (Antarctica) Penguin Data. R package version 0.1.0. doi:10.5281/zenodo.3960218
Note: filename has no default value and must always be supplied
explicitly. Use tempdir() for temporary output during testing or
exploration.
Examples
# \donttest{
# Create a document in a temp directory
create_qmd(path = tempdir(), filename = "analysis.qmd")
#> ✔ Created /tmp/Rtmpip9DJO/data/sample.csv
#> ✔ Created /tmp/Rtmpip9DJO/assets/styles.css
#> ✔ Created /tmp/Rtmpip9DJO/assets/header.html
#> ✔ Created /tmp/Rtmpip9DJO/analysis.qmd
#> ✔ Created /tmp/Rtmpip9DJO/_quarto.yml
#> ✔ Created /tmp/Rtmpip9DJO/R/purl.R
# Create with a custom filename, without the purl hook
create_qmd(path = tempdir(), filename = "report.qmd",
overwrite = TRUE, use_purl = FALSE)
#> ✔ Created /tmp/Rtmpip9DJO/data/sample.csv
#> ✔ Created /tmp/Rtmpip9DJO/assets/styles.css
#> ✔ Created /tmp/Rtmpip9DJO/assets/header.html
#> ✔ Created /tmp/Rtmpip9DJO/report.qmd
# Create with pre-populated YAML
yaml_file <- tempfile(fileext = ".yml")
writeLines("author:\n - name: 'Your Name'", yaml_file)
create_qmd(path = tempdir(), filename = "analysis.qmd",
yaml_data = yaml_file, overwrite = TRUE)
#> ✔ Created /tmp/Rtmpip9DJO/data/sample.csv
#> ✔ Created /tmp/Rtmpip9DJO/assets/styles.css
#> ✔ Created /tmp/Rtmpip9DJO/assets/header.html
#> ✔ Created /tmp/Rtmpip9DJO/analysis.qmd
#> ✔ Created /tmp/Rtmpip9DJO/_quarto.yml
#> ✔ Created /tmp/Rtmpip9DJO/R/purl.R
# }
