str_locate_whichever: Locate the position of one of a series of patterns in a...

Description Usage Arguments Value Examples

Description

Vectorized over string; compares each element of string to every element of patterns. Expects that only one of the patterns provided will match the input string, and returns the position of said match. If the match is of length 0, (e.g. from a special match like $) end will be one character less than start. If more than one of patterns provided match input string, returns position of first matching element from patterns provided. Wraps str_locate with map.

Usage

1

Arguments

string

Input vector. Either a character vector, or something coercible to one.

patterns

Patterns to look for, as a character vector. Each string in the vector may be used as pattern would be in str_locate.

Value

An integer matrix. First column gives start position of whichever pattern matched, and second column gives end position.

Examples

1
2
fruit <- c("apple", "banana", "pear", "pineapple")
str_locate_whichever(fruit, c("ap", "ba", "pe"))

cu-psych-r-users/cuPsychRTools documentation built on July 25, 2019, 5:39 p.m.