Assert an argument has known prototype and/or sizeSource:
vec_is()is a predicate that checks if its input is a vector that conforms to a prototype and/or a size.
vec_assert()throws an error when the input is not a vector or doesn't conform.
vec_assert( x, ptype = NULL, size = NULL, arg = caller_arg(x), call = caller_env() ) vec_is(x, ptype = NULL, size = NULL)
A vector argument to check.
A single integer size against which to compare.
Name of argument being checked. This is used in error messages. The label of the expression passed as
xis taken as default.
The execution environment of a currently running function, e.g.
caller_env(). The function will be mentioned in error messages as the source of the error. See the
abort()for more information.
throws a typed error (see section on error types) or returns
Informally, a vector is a collection that makes sense to use as column in a data frame. An object is a vector if one of the following conditions hold:
vec_proxy()method is implemented for the class of the object.
The base type of the object is atomic:
The object is a data.frame.
The base type is
"list", and one of:
The object is a bare
The object explicitly inherits from
"list". That is, the
Otherwise an object is treated as scalar and cannot be used as a vector. In particular:
NULLis not a vector.
S3 lists like
lmobjects are treated as scalars by default.
Objects of type expression are not treated as vectors.
Support for S4 vectors is currently limited to objects that inherit from an atomic type.
Subclasses of data.frame that append their class to the
"class"attribute are not treated as vectors. If you inherit from an S3 class, always prepend your class to the
"class"attribute for correct dispatch.
vec_is() never throws.
vec_assert() throws the following errors:
If the input is not a vector, an error of class
If the prototype doesn't match, an error of class
If the size doesn't match, an error of class
Both errors inherit from