delimMatch
Delimited Pattern Matching

Description

Matches the delimited substrings in a character vector.

Usage

delimMatch(x, delim = c("{", "}"), syntax = "Rd")

Arguments

x a character vector to be delimited.
delim a character vector. delim must have two delimiters, and each delimiter must be single characters. They can be identical.
syntax a character string. Indicates the syntax used for the delimiter.

Details

Currently, the only syntax supported is Rd. \ is the escape character and % starts a comment extending to the next newline. It includes no quote characters.
Value
returns an integer vector the same length of x giving the position of the first opening delimiter, with the attribute "match.length". Also returns the length of x, giving the number of characters between the opening and matching closing delimiter (including the delimiters).
If the delimiters are distinct, pairs of delimiters can be nested, as in \code{{x1};{y2}}. delimMatch matches the text up to the closing delimiter that is at nesting level 0. In this example, {{x1};{y2}}.
If there is no set of matched delimiters in a string, -1 is returned for both the starting position and the match length.
See Also
parse_Rd, parse
Examples
txt1 <- "\\code{function(x){ x + 1}} is a function definition"
delimMatch(txt1)
regmatches(txt1, delimMatch(txt1))

txt2 <- "% { (brace in comment)\n\\code{log(2)}" regmatches(txt2, delimMatch(txt2))

txt3 <- "This is *very* important. Do it *now*!" regmatches(txt3, delimMatch(txt3, delim=c("*","*")))

Package tools version 6.0.0-69
Package Index