assertion_factories: Assertion factories of package 'typed'

Description Usage Arguments Details Value Examples

Description

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).

Usage

 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, ...)

Arguments

length

length of the object

...

additional conditions, see details.

null_ok

whether NULL values should be accepted, and not subjected to any further check.

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

Details

Additional conditions can be provided :

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())

Value

A function, and more specifically, an assertion as defined above.

Examples

 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)

typed documentation built on March 19, 2021, 5:07 p.m.