# argument to check
arg <- 10
# returns silently if the argument has valid type
check_type(arg, "double")
if (FALSE) {
check_type(arg, "character")
# specify argument's name
check_type(arg, "character", name = "x")
# specify argument `specific` with `glue::glue()` syntax
specific <- "`{name}`'s type is {feature}, which is wrong."
check_type(arg, "character", specific = specific)
# specify argument `supplement`
supplement <- c("You're wrong.", i = "Check your code.")
check_type(arg, "character", supplement = supplement)
# turn off `specific`
check_type(arg, "character", specific = character())
}
# add and retrieve additional argument
tryCatch(
{check_type(arg, "character", your_arg = "your data")},
error = function(e) e$your_arg
)
Run the code above in your browser using DataLab