Description Usage Arguments Details Value Examples
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).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | 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 |
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())
A function, and more specifically, an assertion as defined above.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ## Not run:
# 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)
## End(Not run)
Integer(2) ? x <- 11:12
## Not run:
# We can also use it directly to test assertions
Integer() ? x <- 1
# equivalent to
declare("x", Integer(), value = 1)
Integer(2) ? x <- 1L
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.