option_list = c("default", "par.observed", "empirical")
xmu_match.arg("par.observed", option_list)
xmu_match.arg("allow me", option_list, check = FALSE)
xmu_match.arg(option_list, option_list)
option_list = c(NULL, "par.observed", "empirical")
# fails with NULL!!!!!
xmu_match.arg(option_list, option_list)
option_list = c(NA, "par.observed", "empirical")
xmu_match.arg(option_list, option_list) # use NA instead
option_list = c(TRUE, FALSE, NA)
xmu_match.arg(option_list, option_list) # works with non character
# An example of checking a bad item and stopping
if (FALSE) {
tmp <- function(x= c("one", "two", "three")) {
xmu_match.arg(x, option_list = c("one", "two", "three"))
}
testthat::expect_true(tmp() == "one")
testthat::expect_error(tmp("bad"))
tmp <- function(x= c("one", "two", "three")) {
xmu_match.arg(x, option_list = c("one", "two", "three"), check = FALSE)
}
testthat::expect_true(tmp("OK") == "OK")
testthat::expect_error(tmp(), NA)
}
Run the code above in your browser using DataLab