if (FALSE) {
f <- function(x, y) "Pass"
# Impose a check on x: ensure it's of type "logical"
f_firm <- firmly(f, vld_logical(~x))
f_firm(TRUE, 0) # [1] "Pass"
f_firm(1, 0) # Error: "Not logical: x"
# Use a custom error message
f_firm <- firmly(f, vld_logical("x should be a logical vector" ~ x))
f_firm(1, 0) # Error: "x should be a logical vector"
# To impose the same check on all arguments, apply globalize()
f_firmer <- firmly(f, globalize(vld_logical))
f_firmer(TRUE, FALSE) # [1] "Pass"
f_firmer(TRUE, 0) # Error: "Not logical: `y`"
f_firmer(1, 0) # Errors: "Not logical: `x`", "Not logical: `y`"
}
Run the code above in your browser using DataLab