scalar-checkers {valaddin} | R Documentation |
Scalar checkers
Description
These functions make check formulae of local scope based on the
correspondingly named scalar type predicate from base R. For example,
vld_scalar_logical
creates check formulae (of local scope) for the
predicate is.logical(.) && length(.) == 1
. The function vld_singleton
is
based on the predicate length(.) == 1
.
The functions vld_boolean
, vld_number
, vld_string
are aliases for
vld_scalar_logical
, vld_scalar_numeric
, vld_scalar_character
, resp.
(with appropriately modified error messages).
Usage
vld_boolean(...)
vld_number(...)
vld_scalar_atomic(...)
vld_scalar_character(...)
vld_scalar_complex(...)
vld_scalar_double(...)
vld_scalar_integer(...)
vld_scalar_list(...)
vld_scalar_logical(...)
vld_scalar_numeric(...)
vld_scalar_raw(...)
vld_scalar_vector(...)
vld_singleton(...)
vld_string(...)
Arguments
... |
Check items, i.e., formulae that are one-sided or have a string as left-hand side (see Check Formulae of Local Scope in the documentation page firmly). These are the expressions to check. |
Details
Each function vld_*
is a function of class
"check_maker"
, generated by localize
.
Value
Check formula of local scope.
See Also
Corresponding predicates: is.atomic
, is.character
, is.complex
, is.double
, is.integer
, is.list
, is.logical
, is.numeric
, is.raw
, is.vector
globalize
recovers the underlying check formula of global scope.
The notions of “scope” and “check item” are explained in the Check Formulae section of firmly.
Other checkers: type-checkers, misc-checkers
Examples
## Not run:
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`"
## End(Not run)