x <- c("apple", "banana", "orange")
match_arg("b", x)
# Produces error
try(match_arg("pear", x))
foo <- function(x, op = c(1, 2, 3)) {
op <- match_arg(op)
x / op
}
foo(10, 3)
# Error
try(foo(1, 0))
Run the code above in your browser using DataLab