This function is implemented using tidyselect::eval_select()
which enables
a variety of useful syntax for selecting nodes from the ast.
Additionally, a number of parsermd
helpers are available:
by_section()
, has_type()
, has_label()
, and has_option()
.
Arguments
- x
Rmd object, e.g.
rmd_ast
orrmd_tibble
.- ...
One or more unquoted expressions separated by commas. Chunk labels can be used as if they were positions in the data frame, so expressions like x:y can be used to select a range of nodes.
- keep_yaml
Logical, whether to automatically include YAML nodes in the selection. If
TRUE
(default), equivalent to includinghas_type("rmd_yaml")
in the selection.
See also
rmd_select_helpers for helper functions to use with rmd_select()
, including by_section()
, has_type()
, has_label()
, and has_option()
.
Examples
rmd = parse_rmd(system.file("examples/hw01.Rmd", package = "parsermd"))
rmd_select(rmd, "plot-dino", "cor-dino")
#> ├── YAML [2 fields]
#> ├── Chunk [r, 5 lines] - plot-dino
#> └── Chunk [r, 2 lines] - cor-dino
rmd_select(rmd, "plot-dino":"cor-dino")
#> ├── YAML [2 fields]
#> ├── Chunk [r, 5 lines] - plot-dino
#> ├── Markdown [1 line]
#> └── Chunk [r, 2 lines] - cor-dino
rmd_select(rmd, `plot-dino`:`cor-dino`)
#> ├── YAML [2 fields]
#> ├── Chunk [r, 5 lines] - plot-dino
#> ├── Markdown [1 line]
#> └── Chunk [r, 2 lines] - cor-dino
rmd_select(rmd, has_type("rmd_chunk"))
#> ├── YAML [2 fields]
#> ├── Chunk [r, 2 lines] - load-packages
#> ├── Chunk [r, 5 lines] - plot-dino
#> ├── Chunk [r, 2 lines] - cor-dino
#> ├── Chunk [r, 1 line] - plot-star
#> └── Chunk [r, 1 line] - cor-star
rmd_select(rmd, by_section(c("Exercise *", "Solution")))
#> ├── YAML [2 fields]
#> ├── Heading [h3] - Exercise 1
#> │ └── Heading [h4] - Solution
#> │ └── Markdown [1 line]
#> ├── Heading [h3] - Exercise 2
#> │ └── Heading [h4] - Solution
#> │ ├── Markdown [3 lines]
#> │ ├── Chunk [r, 5 lines] - plot-dino
#> │ ├── Markdown [1 line]
#> │ └── Chunk [r, 2 lines] - cor-dino
#> └── Heading [h3] - Exercise 3
#> └── Heading [h4] - Solution
#> ├── Markdown [3 lines]
#> ├── Chunk [r, 1 line] - plot-star
#> ├── Markdown [1 line]
#> └── Chunk [r, 1 line] - cor-star