Helper functions for obtaining or changing chunk options within an rmd object.
Usage
rmd_set_options(x, ...)
rmd_get_options(x, ..., defaults = list(), yaml_style = TRUE)
Arguments
- x
An
rmd_ast
,rmd_tibble
, or any rmd ast node object.- ...
Either a collection of named values for the setter or a character values of the option names for the getter.
- defaults
A named list of default values for the options.
- yaml_style
logical, if
TRUE
(default) return option names in YAML style (with hyphens), ifFALSE
return normalized style (with dots)
Value
rmd_set_options
returns the modified version of the original object.
rmd_get_options
returns a list of the requested options (or all options if none
are specified). Non-chunk nodes return NULL
.
Examples
rmd = parse_rmd(system.file("examples/minimal.Rmd", package = "parsermd"))
str(rmd_get_options(rmd))
#> List of 12
#> $ : NULL
#> $ : NULL
#> $ :List of 1
#> ..$ include: logi FALSE
#> $ : NULL
#> $ : NULL
#> $ : NULL
#> $ : Named list()
#> $ : Named list()
#> $ : NULL
#> $ : NULL
#> $ :List of 1
#> ..$ echo: logi FALSE
#> $ : NULL
str(rmd_get_options(rmd, "include"))
#> List of 12
#> $ : NULL
#> $ : NULL
#> $ :List of 1
#> ..$ include: logi FALSE
#> $ : NULL
#> $ : NULL
#> $ : NULL
#> $ :List of 1
#> ..$ include: NULL
#> $ :List of 1
#> ..$ include: NULL
#> $ : NULL
#> $ : NULL
#> $ :List of 1
#> ..$ include: NULL
#> $ : NULL
# Get options in YAML style (default) vs normalized style
chunk = rmd_chunk("r", "test", options = list(`fig-width` = 8, eval = TRUE))
rmd_get_options(chunk, yaml_style = TRUE) # fig-width
#> $`fig-width`
#> [1] 8
#>
#> $eval
#> [1] TRUE
#>
rmd_get_options(chunk, yaml_style = FALSE) # fig.width
#> $fig.width
#> [1] 8
#>
#> $eval
#> [1] TRUE
#>
rmd_set_options(rmd, include = TRUE)
#> ├── YAML [4 fields]
#> ├── Heading [h1] - Setup
#> │ └── Chunk [r, 1 line] - setup
#> └── Heading [h1] - Content
#> ├── Heading [h2] - R Markdown
#> │ ├── Markdown [5 lines]
#> │ ├── Chunk [r, 1 line] - cars
#> │ └── Chunk [r, 1 line] - unnamed-chunk-1
#> └── Heading [h2] - Including Plots
#> ├── Markdown [1 line]
#> ├── Chunk [r, 1 line] - pressure
#> └── Markdown [2 lines]