
Match the corresponding indices of (YAML) delimiters in a sequential list
Source:R/match_consecutive_delimiters.R
match_consecutive_delimiters.Rd
This is just a convenience function that takes a vector of deliminaters and returns a list of delimiter pairs.
Usage
match_consecutive_delimiters(
x,
errorOnInvalidX = FALSE,
errorOnOdd = FALSE,
onOddIgnoreFirst = FALSE
)
Arguments
- x
The vector with delimiter indices
- errorOnInvalidX
Whether to return
NA
(ifFALSE
) or throw an error (ifTRUE
) whenx
isNULL
,NA
, or has less than 2 elements.- errorOnOdd
Whether to throw an error if the number of delimiter indices is odd.
- onOddIgnoreFirst
If the number of delimiter indices is odd and no error is thrown, whether to ignore the first (
TRUE
) or the last (FALSE
) delimiter.
Examples
rock::match_consecutive_delimiters(
c(1, 3, 5, 10, 19, 25, 30, 70)
);
#> [[1]]
#> [1] 1 3
#>
#> [[2]]
#> [1] 5 10
#>
#> [[3]]
#> [1] 19 25
#>
#> [[4]]
#> [1] 30 70
#>
exampleText <- c(
"some text",
"delimiter",
"more text",
"delimiter",
"filler text",
"intentionally left blank",
"delimiter",
"final text",
"delimiter"
);
rock::match_consecutive_delimiters(
grep(
"delimiter",
exampleText
)
);
#> [[1]]
#> [1] 2 4
#>
#> [[2]]
#> [1] 7 9
#>