split_nth: Split at nth pattern

View source: R/utils.R

split_nthR Documentation

Split at nth pattern

Description

Split a string at the nth occurrence(s) of a pattern.

Usage

split_nth(text, pattern, n = NULL, keep_split = FALSE, repl = "$$$", ...)

Arguments

text, pattern

the text and pattern character strings

n

integer value(s) for splitting at the nth occurrence of pattern; NULL will split at each pattern

keep_split

logical; if TRUE, text will be split at the boundaries of pattern

repl

a string used internally for place-keeping during splitting; to avoid unexpected results, make sure this string does not occur in text

...

additional arguments passed to gregexpr

Examples

s <- 'this  is a  test string to use   for testing   purposes'
split_nth(s, '\\s+')
split_nth(s, '\\s+', 3)
split_nth(s, '\\s+', c(3, 5))
split_nth(s, '\\s+', c(3, 5), keep_split = TRUE)
split_nth(s, '\\s{2,}', keep_split = TRUE)
split_nth(s, '\\s{2,}', 2:4)


raredd/rawr documentation built on March 4, 2024, 1:36 a.m.