pmatchSafe | R Documentation |
This function is the same as pmatch
, but it can throw an error instead of NA
if not match is found, and can be forced to throw the error if more than the desired number of matches is found.
pmatchSafe(
x,
table,
useFirst = FALSE,
error = TRUE,
ignoreCase = TRUE,
nmax = length(x),
...
)
x |
Character: String to match. |
table |
Character vector: Values to which to match. |
useFirst |
Logical: If |
error |
Logical: If no match is found, return an error? |
ignoreCase |
Logical: If |
nmax |
Positive numeric integer: Maximum allowable number of matches. If more than this number of matches is found, an error will be thrown (regardless of the value of |
... |
Arguments to pass to |
One or more of the values in table
.
pmatchSafe('ap', c('apples', 'oranges', 'bananas'))
pmatchSafe('AP', c('apples', 'oranges', 'bananas'))
pmatchSafe('AP', c('apples', 'oranges', 'bananas'),
ignoreCase = FALSE, error = FALSE)
pmatchSafe(c('ba', 'ap'), c('apples', 'oranges', 'bananas'))
# No match:
tryCatch(
pmatchSafe('kumquats', c('apples', 'oranges', 'bananas')),
error = function(cond) FALSE
)
pmatchSafe('kumquats', c('apples', 'oranges', 'bananas'), error = FALSE)
pmatchSafe(c('ap', 'corn'), c('apples', 'oranges', 'bananas'), error = FALSE)
# Too many matches:
tryCatch(
pmatchSafe(c('ap', 'ba'), c('apples', 'oranges', 'bananas'), nmax = 1),
error=function(cond) FALSE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.