rmd_select_helpers: Rmd selection helper functions

Description Usage Arguments Details Value Examples

Description

These functions are used in conjunction with rmd_select() to select nodes from an Rmd ast.

Usage

1
2
3
4
5
6
7
has_type(types)

by_section(sec_ref, keep_parents = TRUE)

has_label(label)

has_option(...)

Arguments

types

Vector of character type names, e.g. rmd_chunk, rmd_heading, etc.

sec_ref

character vector, a section reference selector. See details below for further details on how these are constructed.

keep_parents

Logical, retain the parent headings of selected sections. Default: TRUE

label

character vector, glob patterns for matching chunk labels.

...

Either option names represented by a scalar string or a named argument with the form opt = value where opt is the option name and value is the value to be checked. For example eval = TRUE would check for the option eval being set to TRUE.

Details

Section reference selectors

Section reference selectors are a simplified version of CSS selectors that are designed to enable the selection nodes in a way that respects the implied hierarchy of a document's section headings.

They consist of a character vector of heading names where each subsequent value is assumed to be nested within the preceding value. For example, the section selector c("Sec 1", "Sec 2") would select all nodes that are contained within a section named Sec 2 that is in turn contained within a section named Sec 1 (or a section contained within a section named Sec 1, and so on).

The individual section names can be specified using wildcards (aka globbing patterns), which may match one or more sections within the document, e.g. c("Sec 1", "Sec *"). See utils::glob2rx() or wikipedia for more details on the syntax for these patterns.

Value

All helper functions return an integer vector of selected indexes.

Examples

1
2
3
4
5
6
7
8
9
rmd = parse_rmd(system.file("hw01.Rmd", package="parsermd"))

rmd_select(rmd, has_type("rmd_chunk"))

rmd_select(rmd, has_label("*dino"))

rmd_select(rmd, has_option("message"))
rmd_select(rmd, has_option(message = FALSE))
rmd_select(rmd, has_option(message = TRUE))

parsermd documentation built on May 20, 2021, 5:08 p.m.