R/find_yaml_fragment_indices.R
find_yaml_fragment_indices.Rd
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.
find_yaml_fragment_indices(
file,
text,
invert = FALSE,
returnFragmentIndices = TRUE,
returnPairedIndices = TRUE,
delimiterRegEx = "^---$",
ignoreOddDelimiters = FALSE,
silent = TRUE
)
The path to a file to scan; if provided, takes precedence
over text
.
A character vector to scan, where every element should
represent one line in the file; can be specified instead of file
.
Set to TRUE
to return the indices of the character
vector that are not YAML fragments.
Set to TRUE
to return all indices of the
relevant fragments (i.e. including intermediate indices).
Whether to return two vectors with the start and end indices, or pair them up in vectors of 2.
The regular expression used to locate YAML fragments.
Whether to throw an error (FALSE) or delete the last delimiter (TRUE) if an odd number of delimiters is encountered.
Whether to be silent (TRUE) or informative (FALSE).
A list of numeric vectors with start and end indices
### 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
);
#> [[1]]
#> [1] 1 2 3
#>
#> [[2]]
#> [1] 6 7 8
#>
yum::find_yaml_fragment_indices(
text=simpleExampleText,
returnFragmentIndices = FALSE
);
#> [[1]]
#> [1] 1 3
#>
#> [[2]]
#> [1] 6 8
#>
yum::find_yaml_fragment_indices(
text=simpleExampleText,
invert = TRUE
);
#> [[1]]
#> [1] 4 5
#>
#> [[2]]
#> [1] 9 10 11
#>