find_yaml_fragment_indices: Find the indices ('line numbers') of all YAML fragments from...

Description Usage Arguments Value Examples

View source: R/find_yaml_fragment_indices.R

Description

These function finds all YAML fragments from a file, returning their start and end indices or all indices of all lines in the (non-)YAML fragments.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
find_yaml_fragment_indices(
  file,
  text,
  invert = FALSE,
  returnFragmentIndices = TRUE,
  returnPairedIndices = TRUE,
  delimiterRegEx = "^---$",
  ignoreOddDelimiters = FALSE,
  silent = TRUE
)

Arguments

file

The path to a file to scan; if provided, takes precedence over text.

text

A character vector to scan, where every element should represent one line in the file; can be specified instead of file.

invert

Set to TRUE to return the indices of the character vector that are not YAML fragments.

returnFragmentIndices

Set to TRUE to return all indices of the relevant fragments (i.e. including intermediate indices).

returnPairedIndices

Whether to return two vectors with the start and end indices, or pair them up in vectors of 2.

delimiterRegEx

The regular expression used to locate YAML fragments.

ignoreOddDelimiters

Whether to throw an error (FALSE) or delete the last delimiter (TRUE) if an odd number of delimiters is encountered.

silent

Whether to be silent (TRUE) or informative (FALSE).

Value

A list of numeric vectors with start and end indices

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
### Create simple text vector with the right delimiters
simpleExampleText <-
  c(
    "---",
    "First YAML fragment",
    "---",
    "Outside of YAML",
    "This, too.",
    "---",
    "Second fragment",
    "---",
    "Also outside of YAML",
    "Another one outside",
    "Last one"
  );

yum::find_yaml_fragment_indices(
  text=simpleExampleText
);

yum::find_yaml_fragment_indices(
  text=simpleExampleText,
  returnFragmentIndices = FALSE
);

yum::find_yaml_fragment_indices(
  text=simpleExampleText,
  invert = TRUE
);

yum documentation built on July 17, 2021, 1:07 a.m.