These functions are assertion factories, they produce assertions, which take an object, check conditions, and returns the input, usually unmodified (never modified with the functions documented on this page).
Any(length, ...) Logical(length, null_ok = FALSE, ...) Integer(length, null_ok = FALSE, ...) Double(length, null_ok = FALSE, ...) Character(length, null_ok = FALSE, ...) Raw(length, null_ok = FALSE, ...) List(length, each, data_frame_ok, null_ok = FALSE, ...) Null(...) Closure(null_ok = FALSE, ...) Special(null_ok = FALSE, ...) Builtin(null_ok = FALSE, ...) Environment(null_ok = FALSE, ...) Symbol(null_ok = FALSE, ...) Pairlist(length, each, null_ok = TRUE, ...) Language(null_ok = FALSE, ...) Expression(length, null_ok = FALSE, ...) Function(null_ok = FALSE, ...) Factor(length, levels, null_ok = FALSE, ...) Matrix(nrow, ncol, null_ok = FALSE, ...) Array(dim, null_ok = FALSE, ...) Data.frame(nrow, ncol, each, null_ok = FALSE, ...) Date(length, null_ok = FALSE, ...) Time(length, null_ok = FALSE, ...) Dots(length, each, ...) Logical(length, null_ok = FALSE, ...) Integer(length, null_ok = FALSE, ...) Double(length, null_ok = FALSE, ...) Character(length, null_ok = FALSE, ...) Raw(length, null_ok = FALSE, ...) List(length, each, data_frame_ok = TRUE, null_ok = FALSE, ...) Null(...) Closure(null_ok = FALSE, ...) Special(null_ok = FALSE, ...) Builtin(null_ok = FALSE, ...) Environment(null_ok = FALSE, ...) Symbol(null_ok = FALSE, ...) Pairlist(length, each, null_ok = TRUE, ...) Language(null_ok = FALSE, ...) Expression(length, null_ok = FALSE, ...) Function(null_ok = FALSE, ...) Factor(length, levels, null_ok = FALSE, ...) Data.frame(nrow, ncol, each, null_ok = FALSE, ...) Matrix(nrow, ncol, null_ok = FALSE, ...) Array(dim, null_ok = FALSE, ...) Date(length, null_ok = FALSE, ...) Time(length, null_ok = FALSE, ...) Dots(length, each, ...)
length | length of the object |
---|---|
... | additional conditions, see details. |
null_ok | whether |
each | assertion that every item must satisfy |
data_frame_ok | whether data frames are to be considered as lists |
levels | factor levels |
nrow | number of rows |
ncol | number of columns |
dim | dimensions |
A function, and more specifically, an assertion as defined above.
Additional conditions can be provided :
If they are named, the name should be the name of a function to use on our object, and the value should be the expected value.
If they are unnamed, they should be formulas, the right hand side should
be a condition, using value
or .
as a placeholder for the latter, and
the optional lhs
an error message.
Any
is the most general assertion factory, it doesn't check anything unless
provided additional conditions through ...
. Others use the base is.<type>
function
if available, or check that the object is of the relevant type with typeof
for atomic types, or check that the class of the checked value contains
the relevant class.
Dots
should only be used to check the dots using check_arg
on list(...)
or substitute(...())
, which will
be the case when it's called respectively with function(... = ? Dots())
and function(... = ?~ Dots())
if (FALSE) { # fails Integer() ? x <- 1 # equivalent to declare("x", Integer(), value = 1) Integer(2) ? x <- 1L # we can use additional conditions in `...` Integer(anyNA = FALSE) ? x <- c(1L, NA, 1L) Integer(anyDuplicated = FALSE) ? x <- c(1L, NA, 1L) } Integer(2) ? x <- 11:12 if (FALSE) { # We can also use it directly to test assertions Integer() ? x <- 1 # equivalent to declare("x", Integer(), value = 1) Integer(2) ? x <- 1L }