target that are partially matched by
input
.
charmatch(input, target, nomatch=NA)
input does not partially match any
string in
target.
input containing the index of
target that
partially matches
input.
If none of the elements of
target match,
nomatch is returned.
If it is an ambiguous match, a
0 is returned.
This function is useful for processing the arguments to functions.
It is very similar to the
pmatch function.
However,
pmatch does not allow a distinction between no match and
an ambiguous match.
The
pmatch function does not allow a match to the empty string, while
charmatch
does.
charmatch("mea", c("mean", "median", "mode")) # returns 1
charmatch("m", c("mean", "median", "mode")) # returns 0
pmatch("m", c("mean", "median", "mode")) # returns NA
charmatch(c("sin", "cot"), c("cos", "sin", "tan"), nomatch = -1)
# returns c(2, -1)
charmatch("","") # returns 1
pmatch("","") # returns NA