if (FALSE) {
f <- function(x, y) "Pass"
# Impose a check on x: ensure it's boolean (i.e., a scalar logical vector)
f_firm <- firmly(f, vld_boolean(~x))
f_firm(TRUE, 0) # [1] "Pass"
f_firm(c(TRUE, TRUE), 0) # Error: "Not boolean: x"
# Use a custom error message
f_firm <- firmly(f, vld_boolean("x is not TRUE/FALSE/NA" ~ x))
f_firm(c(TRUE, TRUE), 0) # Error: "x is not TRUE/FALSE/NA"
# To impose the same check on all arguments, apply globalize
f_firmer <- firmly(f, globalize(vld_boolean))
f_firmer(TRUE, FALSE) # [1] "Pass"
f_firmer(TRUE, 0) # Error: "Not boolean: `y`"
f_firmer(logical(0), 0) # Errors: "Not boolean: `x`", "Not boolean: `y`"
}
Run the code above in your browser using DataLab