misc-checkers {valaddin} | R Documentation |
Miscellaneous checkers
Description
These functions make check formulae of local scope based on the
correspondingly named base R predicates is.*
(e.g.,
vld_data_frame
corresponds to the predicate
is.data.frame
), with the following exceptions:
-
vld_empty
is based on the predicatelength(.) == 0
-
vld_formula
is based on the predicatetypeof(.) == "language" && inherits(., "formula")
-
vld_closure
is based on the predicatetypeof(.) == "closure"
-
vld_true
andvld_false
are based on the predicatesidentical(., TRUE)
andidentical(., FALSE)
, resp.
The checkers vld_true
and vld_false
are all-purpose checkers to
specify arbitrary input validation checks.
Usage
vld_all(...)
vld_any(...)
vld_array(...)
vld_atomic(...)
vld_call(...)
vld_closure(...)
vld_data_frame(...)
vld_empty(...)
vld_environment(...)
vld_expression(...)
vld_factor(...)
vld_false(...)
vld_formula(...)
vld_function(...)
vld_language(...)
vld_list(...)
vld_matrix(...)
vld_na(...)
vld_name(...)
vld_nan(...)
vld_null(...)
vld_numeric(...)
vld_ordered(...)
vld_pairlist(...)
vld_primitive(...)
vld_recursive(...)
vld_symbol(...)
vld_table(...)
vld_true(...)
vld_unsorted(...)
vld_vector(...)
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: all
, any
, is.array
, is.atomic
, is.call
, is.data.frame
, is.environment
, is.expression
, is.factor
, is.function
, is.language
, is.list
, is.matrix
, is.na
, is.name
, is.nan
, is.null
, is.numeric
, is.ordered
, is.pairlist
, is.primitive
, is.recursive
, is.symbol
, is.table
, is.unsorted
, 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, scalar-checkers
Examples
## Not run:
f <- function(x, y) "Pass"
# Impose the condition that x is a formula
g <- firmly(f, vld_formula(~x))
g(z ~ a + b, 0) # [1] "Pass"
g(0, 0) # Error: "Not formula: x"
# Impose the condition that x and y are disjoint (assuming they are vectors)
h <- firmly(f, vld_empty(~intersect(x, y)))
h(letters[1:3], letters[4:5]) # [1] "Pass"
h(letters[1:3], letters[3:5]) # Error: "Not empty: intersect(x, y)"
# Use a custom error message
h <- firmly(f, vld_empty("x, y must be disjoint" ~ intersect(x, y)))
h(letters[1:3], letters[3:5]) # Error: "x, y must be disjoint"
# vld_true can be used to implement any kind of input validation
ifelse_f <- firmly(ifelse, vld_true(~typeof(yes) == typeof(no)))
(w <- {set.seed(1); rnorm(5)})
# [1] -0.6264538 0.1836433 -0.8356286 1.5952808 0.3295078
ifelse_f(w > 0, 0, "1") # Error: "Not TRUE: typeof(yes) == typeof(no)"
ifelse_f(w > 0, 0, 1) # [1] 1 0 1 0 0
## End(Not run)