fruits <- function(x = c("apple", "banana", "orange")) {
match_param(x)
}
fruits() # apple
try(fruits("b")) # must be exact fruits("banana")
pfruits <- function(x = c("apple", "apricot", "banana")) {
match_param(x, partial = TRUE)
}
pfruits() # apple
try(pfruits("ap")) # matchParamMatchError
pfruits("app") # apple
afruits <- function(x = c("apple", "banana", "orange")) {
match_param(x, multiple = TRUE)
}
afruits() # apple, banana, orange
# can have multiple responses
how_much <- function(x = list(too_few = 0:2, ok = 3:5, too_many = 6:10)) {
match_param(x)
}
how_much(1)
how_much(3)
how_much(9)
# use a list of formulas instead
ls <- list(1L ~ 0:1, 2L, 3L ~ 3:5)
sapply(0:5, match_param, choices = ls)
Run the code above in your browser using DataLab