checkValue: Check functions for values

Description Usage Arguments Details Value Functions Examples

Description

A check function test something about its first (required) parameter and returns either an empty string if the check succeeds or a non-empty string if the check fails. Even when a test fails due to an error, the error is caught and a message will be returned. The check functions described here test various properties of values.

Usage

1
2
3
4
5
6
7
8
9
checkIsNull(value)

checkIsNotNull(value)

checkLength(value, minimumLength = 0, maximumLength = Inf)

checkIsTrue(value)

checkIsFalse(value)

Arguments

value

A value to check.

minimumLength

The minimum length value must have. Shorter than this and the check will fail. The default is 0. Often abbreviated 'min'.

maximumLength

The maximum length value must have. Longer than this and the check will fail. The default is Inf. Often abbreviated 'max'.

Details

Many of the these functions are simple wrappers around existing R functions. Note, calling any of these functions with an unused parameters will cause an actual error as that is thrown before the called function begins executing and hence can not be trapped and converted to a message by the called function.

Value

All functions return either an empty string if the check succeeds or a non-empty string if the check fails (including if checking causes an error.)

Functions

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
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
# Ensuring a value is NULL
checkIsNull( NULL )
#=> [1] ""
checkIsNull( NA )
#=> [1] "Is not null."
checkIsNull()
#=> [1] "Checking for null failed with the following error:
#=> argument \"value\" is missing, with no default"

# Testing a value for existence
checkIsNotNull( NA )
#=> [1] ""
checkIsNotNull( NULL )
#=> [1] "Is null."

checkIsNotNull()
#=> [1] "Checking for null failed with the following error:
#=> argument \"value\" is missing, with no default"

# Testing the length of a value.
checkLength( character(0) )
#=> [1] ""
checkLength( c(1, 2), minimumLength= 2 )
#=> [1] ""
checkLength( c(1, 2), minimumLength= 3 )
#=> [1] "Length is not between 3 and Inf."
checkLength( c(1, 2), max= 1 )
#=> [1] "Length is not between 0 and 1."
checkLength( c(1, 2), min= 2, max= 2 )
#=> [1] ""
checkLength( c(1, 2, 3), min= 2, max= 2 )
#=> [1] "Length is not 2."
checkLength( NULL )
#=> [1] "Bad parameter 'value'. Is null."

# Checking an expression for truth
checkIsTrue( TRUE )
#=> [1] ""
checkIsTrue( 1 + 1 == 2 )
#=> [1] ""
checkIsTrue({
   x <- 1
   y <- 1
   x == y
})
checkIsTrue( FALSE )
#=> [1] "Is false."
checkIsTrue( FALSE == NA )
#=> [1] "Is NA."
checkIsTrue({ x <- c(T,T,F); all(x) })
#=> [1] "Is false."
checkIsTrue( c(T,T,T) )
#=> [1] "Resulting logical vector is not of length 1."
checkIsTrue( "true" )
#=> [1] "Result is not a vector of mode logical."
checkIsTrue( NULL )
#=> [1] "Result is not a vector of mode logical."
checkIsTrue( stop('Oops.') )
#=> [1] ""Checking expression for truth failed with the following error: Oops."

# Checking an expression for falsehood
checkIsFalse( TRUE )
#=> [1] ""
checkIsFalse( 1 + 1 == 3 )
#=> [1] ""
checkIsFalse({
   x <- 1
   y <- 2
   x == y
})
checkIsFalse( TRUE )
#=> [1] "Is true"
checkIsFalse( TRUE == NA )
#=> [1] "Is NA."
checkIsFalse({ x <- c(T,T,F); any(x) })
#=> [1] "Is false."
checkIsFalse( c(F,F,F) )
#=> [1] "Resulting logical vector is not of length 1."
checkIsFalse( "false" )
#=> [1] "Result is not a vector of mode logical."
checkIsFalse( NULL )
#=> [1] "Result is not a vector of mode logical."
checkIsFalse( stop('Oops.') )
#=> [1] "Checking expression for falsehood failed with the following error: Oops."

jefferys/DataRepo documentation built on May 19, 2019, 3:58 a.m.