ore_switch: String multiplexing

Description Usage Arguments Value See Also Examples


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.


ore_switch(text, ..., options = "", encoding = getOption("ore.encoding"))



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 text element if the regex matches (and no previous one matched). These strings may reference captured groups. Unnamed arguments match unconditionally, and will always be taken literally.


A string composed of characters indicating variations on the usual interpretation of the regex. These may currently include "i" for case-insensitive matching, and "m" for multiline matching (in which case "." matches the newline character).


A string specifying the encoding that matching will take place in. The default is given by the "ore.encoding" option, which is usually set automatically from the current locale when the package is loaded, but can be modified if needed.


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.


# Extract digits where present; otherwise return zero
ore_switch(c("2 dogs","no dogs"), "\\d+"="\\0", "0")

ore documentation built on Nov. 2, 2021, 5:08 p.m.