example_fun <- function(msg_type) {
assert_character_scalar(msg_type, values = c("warning", "error"))
}
example_fun("warning")
try(example_fun("message"))
try(example_fun(TRUE))
# handling arguments case-insensitive
example_fun2 <- function(msg_type) {
msg_type <- assert_character_scalar(
msg_type,
values = c("warning", "error"),
case_sensitive = FALSE
)
if (msg_type == "warning") {
print("A warning was requested.")
}
}
example_fun2("Warning")
Run the code above in your browser using DataLab