Learn R Programming

rock (version 0.8.1)

match_consecutive_delimiters: Match the corresponding indices of (YAML) delimiters in a sequential list

Description

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
)

Value

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

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.

Examples

Run this code
rock::match_consecutive_delimiters(
  c(1, 3, 5, 10, 19, 25, 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
  )
);

Run the code above in your browser using DataLab