This is just a convenience function that takes a vector of deliminaters and returns a list of delimiter pairs.

match_consecutive_delimiters(
  x,
  errorOnInvalidX = FALSE,
  errorOnOdd = FALSE,
  onOddIgnoreFirst = FALSE
)

Arguments

x

The vector with delimiter indices

errorOnInvalidX

Whether to return NA (if FALSE) or throw an error (if TRUE) when x is NULL, 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.

Value

A list where each element is a two-element vector with the two consecutive delimiters

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
#>