ore_switch {ore} | R Documentation |
String multiplexing
Description
This function maps one character vector to another, based on sequential matching to a series of regular expressions. The return value corresponding to each element in the source text is chosen based on the first matching regex: once matched, later options are ignored.
Usage
ore_switch(text, ..., options = "", encoding = getOption("ore.encoding"))
Arguments
text |
A vector of strings to match against. |
... |
One or more string arguments specifying a possible return value.
These are generally named with a regex, and the string is only used for a
given |
options |
A string composed of characters indicating variations on the
usual interpretation of the regex. These may currently include |
encoding |
A string specifying the encoding that matching will take
place in. The default is given by the |
Value
A character vector of the same length as text
, containing the
multiplexed strings. If none of the regexes matched, the corresponding
element will be NA
.
See Also
ore_subst
for details of back-reference syntax.
Examples
# Extract digits where present; otherwise return zero
ore_switch(c("2 dogs","no dogs"), "\\d+"="\\0", "0")