Debian Codegraph @

man/knit_params.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/params.R
3 \name{knit_params}
4 \alias{knit_params}
5 \title{Extract knit parameters from a document}
6 \usage{
7 knit_params(text, evaluate = TRUE)
8 }
9 \arguments{
10 \item{text}{Character vector containing the document text.}
11
12 \item{evaluate}{Boolean. If \code{TRUE} (the default), expression values embedded
13 within the YAML will be evaluated. If \code{FALSE}, parameters defined with an
14 expression will have the parsed but unevaluated expression in their \code{value}
15 field.}
16 }
17 \value{
18 List of objects of class \code{knit_param} that correspond to the
19 parameters declared in the \code{params} section of the YAML front matter.
20 These objects have the following fields:
21
22 \describe{
23 \item{\code{name}}{The parameter name.}
24 \item{\code{value}}{The default value for the parameter.}
25 \item{\code{expr}}{The R expression (if any) that yielded the default value.}
26 }
27
28 In addition, other fields included in the YAML may also be present
29 alongside the name, type, and value fields (e.g. a \code{label} field
30 that provides front-ends with a human readable name for the parameter).
31 }
32 \description{
33 This function reads the YAML front-matter section of a document and returns a
34 list of any parameters declared there. This function exists primarily to
35 support the parameterized reports feature of the \pkg{rmarkdown} package,
36 however is also used by the knitr \code{\link{purl}} function to include
37 the default parameter values in the R code it emits.
38 }
39 \details{
40 Parameters are included in YAML front matter using the \code{params} key.
41 This key can have any number of subkeys each of which represents a
42 parameter. For example:
43
44 \preformatted{
45 ---
46 title: My Document
47 output: html_document
48 params:
49 frequency: 10
50 show_details: true
51 ---
52 }
53
54 Parameter values can be provided inline as illustrated above or can be
55 included in a \code{value} sub-key. For example:
56
57 \preformatted{
58 ---
59 title: My Document
60 output: html_document
61 params:
62 frequency:
63 value: 10
64 ---
65 }
66
67 This second form is useful when you need to provide additional details
68 about the parameter (e.g. a \code{label} field as describe above).
69
70 You can also use R code to yield the value of a parameter by prefacing the value
71 with \code{!r}, for example:
72
73 \preformatted{
74 ---
75 title: My Document
76 output: html_document
77 params:
78 start: !r Sys.Date()
79 ---
80 }
81 }