Title: | Fast and Versatile Argument Checks |
---|---|
Description: | Tests and assertions to perform frequent argument checks. A substantial part of the package was written in C to minimize any worries about execution time overhead. |
Authors: | Michel Lang [cre, aut] , Bernd Bischl [ctb], Dénes Tóth [ctb] |
Maintainer: | Michel Lang <[email protected]> |
License: | BSD_3_clause + file LICENSE |
Version: | 2.3.2 |
Built: | 2024-10-27 05:05:58 UTC |
Source: | https://github.com/mllg/checkmate |
Tests and assertions to perform frequent argument checks. A substantial part of the package was written in C to minimize any worries about execution time overhead.
checkNamed
(deprecated)
checkOS
(check operating system)
assert
(combine multiple checks into an assertion)
wf
(which.first and which.last)
Maintainer: Michel Lang [email protected] (ORCID)
Other contributors:
Bernd Bischl [email protected] [contributor]
Dénes Tóth [email protected] (ORCID) [contributor]
Useful links:
Report bugs at https://github.com/mllg/checkmate/issues
Returns the left hand side if not missing nor NULL
, and
the right hand side otherwise.
lhs %??% rhs
lhs %??% rhs
lhs |
[any] |
rhs |
[any] |
Either lhs
or rhs
.
print(NULL %??% 1 %??% 2) print(names(iris) %??% letters[seq_len(ncol(iris))])
print(NULL %??% 1 %??% 2) print(names(iris) %??% letters[seq_len(ncol(iris))])
anyMissing
checks for the presence of at least one missing value,
allMissing
checks for the presence of at least one non-missing value.
Supported are atomic types (see is.atomic
), lists and data frames.
Missingness is defined as NA
or NaN
for atomic types and data frame columns,
NULL
is defined as missing for lists.allMissing
applied to a data.frame
returns TRUE
if at least one column has
only non-missing values. If you want to perform the less frequent check that there is at least
a single non-missing observation present in the data.frame
, use
all(sapply(df, allMissing))
instead.
allMissing(x) anyMissing(x)
allMissing(x) anyMissing(x)
x |
[ |
[logical(1)
] Returns TRUE
if any (anyMissing
) or all (allMissing
)
elements of x
are missing (see details), FALSE
otherwise.
allMissing(1:2) allMissing(c(1, NA)) allMissing(c(NA, NA)) x = data.frame(a = 1:2, b = NA) # Note how allMissing combines the results for data frames: allMissing(x) all(sapply(x, allMissing)) anyMissing(c(1, 1)) anyMissing(c(1, NA)) anyMissing(list(1, NULL)) x = iris x[, "Species"] = NA anyMissing(x) allMissing(x)
allMissing(1:2) allMissing(c(1, NA)) allMissing(c(NA, NA)) x = data.frame(a = 1:2, b = NA) # Note how allMissing combines the results for data frames: allMissing(x) all(sapply(x, allMissing)) anyMissing(c(1, 1)) anyMissing(c(1, NA)) anyMissing(list(1, NULL)) x = iris x[, "Species"] = NA anyMissing(x) allMissing(x)
Supported are atomic types (see is.atomic
), lists and data frames.
anyInfinite(x)
anyInfinite(x)
x |
[ |
[logical(1)
] Returns TRUE
if any element is -Inf
or Inf
.
anyInfinite(1:10) anyInfinite(c(1:10, Inf)) iris[3, 3] = Inf anyInfinite(iris)
anyInfinite(1:10) anyInfinite(c(1:10, Inf)) iris[3, 3] = Inf anyInfinite(iris)
Supported are atomic types (see is.atomic
), lists and data frames.
anyNaN(x)
anyNaN(x)
x |
[ |
[logical(1)
] Returns TRUE
if any element is NaN
.
anyNaN(1:10) anyNaN(c(1:10, NaN)) iris[3, 3] = NaN anyNaN(iris)
anyNaN(1:10) anyNaN(c(1:10, NaN)) iris[3, 3] = NaN anyNaN(iris)
asInteger
is intended to be used for vectors while asInt
is
a specialization for scalar integers and asCount
for scalar
non-negative integers.
Convertible are (a) atomic vectors with all elements NA
and (b) double vectors with all elements being within tol
range of an integer.
Note that these functions may be deprecated in the future.
Instead, it is advised to use assertCount
,
assertInt
or assertIntegerish
with
argument coerce
set to TRUE
instead.
asInteger( x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, .var.name = vname(x) ) asCount( x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), .var.name = vname(x) ) asInt( x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), .var.name = vname(x) )
asInteger( x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, .var.name = vname(x) ) asCount( x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), .var.name = vname(x) ) asInt( x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), .var.name = vname(x) )
x |
[any] |
tol |
[ |
lower |
[ |
upper |
[ |
any.missing |
[ |
all.missing |
[ |
len |
[ |
min.len |
[ |
max.len |
[ |
unique |
[ |
sorted |
[ |
names |
[ |
.var.name |
[ |
na.ok |
[ |
positive |
[ |
This function does not distinguish between
NA
, NA_integer_
, NA_real_
, NA_complex_
NA_character_
and NaN
.
Converted x
.
asInteger(c(1, 2, 3)) asCount(1) asInt(1)
asInteger(c(1, 2, 3)) asCount(1) asInt(1)
You can call this function with an arbitrary number of of check*
functions, i.e. functions provided by this package or your own functions which
return TRUE
on success and the error message as character(1)
otherwise.
The resulting assertion is successful, if combine
is
“or” (default) and at least one check evaluates to TRUE
or
combine
is “and” and all checks evaluate to TRUE
.
Otherwise, assert
throws an informative error message.
assert(..., combine = "or", .var.name = NULL, add = NULL)
assert(..., combine = "or", .var.name = NULL, add = NULL)
... |
[any] |
combine |
[ |
.var.name |
[ |
add |
[ |
Throws an error (or pushes the error message to an
AssertCollection
if add
is not NULL
)
if the checks fail and invisibly returns TRUE
otherwise.
x = 1:10 assert(checkNull(x), checkInteger(x, any.missing = FALSE)) collection <- makeAssertCollection() assert(checkChoice(x, c("a", "b")), checkDataFrame(x), add = collection) collection$getMessages()
x = 1:10 assert(checkNull(x), checkInteger(x, any.missing = FALSE)) collection <- makeAssertCollection() assert(checkChoice(x, c("a", "b")), checkDataFrame(x), add = collection) collection$getMessages()
The function makeAssertCollection()
returns a simple stack-like
closure you can pass to all functions of the assert*
-family.
All messages get collected and can be reported with reportAssertions()
.
Alternatively, you can easily write your own report function or customize the the output of
the report function to a certain degree.
See the example on how to push custom messages or retrieve all stored messages.
makeAssertCollection() reportAssertions(collection)
makeAssertCollection() reportAssertions(collection)
collection |
[ |
makeAssertCollection()
returns an object of class “AssertCollection” and
reportCollection
returns invisibly TRUE
if no error is thrown (i.e., no message was
collected).
x = "a" coll = makeAssertCollection() print(coll$isEmpty()) assertNumeric(x, add = coll) coll$isEmpty() coll$push("Custom error message") coll$getMessages() ## Not run: reportAssertions(coll) ## End(Not run)
x = "a" coll = makeAssertCollection() print(coll$isEmpty()) assertNumeric(x, add = coll) coll$isEmpty() coll$push("Custom error message") coll$getMessages() ## Not run: reportAssertions(coll) ## End(Not run)
Check file system access rights
checkAccess(x, access = "") check_access(x, access = "") assertAccess(x, access = "", .var.name = vname(x), add = NULL) assert_access(x, access = "", .var.name = vname(x), add = NULL) testAccess(x, access = "") test_access(x, access = "") expect_access(x, access = "", info = NULL, label = vname(x))
checkAccess(x, access = "") check_access(x, access = "") assertAccess(x, access = "", .var.name = vname(x), add = NULL) assert_access(x, access = "", .var.name = vname(x), add = NULL) testAccess(x, access = "") test_access(x, access = "") expect_access(x, access = "", info = NULL, label = vname(x))
x |
[any] |
access |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertAccess
/assert_access
return
x
invisibly, whereas
checkAccess
/check_access
and
testAccess
/test_access
return
TRUE
.
If the check is not successful,
assertAccess
/assert_access
throws an error message,
testAccess
/test_access
returns FALSE
,
and checkAccess
/check_access
return a string with the error message.
The function expect_access
always returns an
expectation
.
Other filesystem:
checkDirectoryExists()
,
checkFileExists()
,
checkPathForOutput()
# Is R's home directory readable? testAccess(R.home(), "r") # Is R's home directory writeable? testAccess(R.home(), "w")
# Is R's home directory readable? testAccess(R.home(), "r") # Is R's home directory writeable? testAccess(R.home(), "w")
Check if an argument is an array
checkArray( x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL, null.ok = FALSE ) check_array( x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL, null.ok = FALSE ) assertArray( x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_array( x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testArray( x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL, null.ok = FALSE ) test_array( x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL, null.ok = FALSE ) expect_array( x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
checkArray( x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL, null.ok = FALSE ) check_array( x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL, null.ok = FALSE ) assertArray( x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_array( x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testArray( x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL, null.ok = FALSE ) test_array( x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL, null.ok = FALSE ) expect_array( x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
mode |
[ |
any.missing |
[ |
d |
[ |
min.d |
[ |
max.d |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertArray
/assert_array
return
x
invisibly, whereas
checkArray
/check_array
and
testArray
/test_array
return
TRUE
.
If the check is not successful,
assertArray
/assert_array
throws an error message,
testArray
/test_array
returns FALSE
,
and checkArray
/check_array
return a string with the error message.
The function expect_array
always returns an
expectation
.
Other basetypes:
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
Other compound:
checkDataFrame()
,
checkDataTable()
,
checkMatrix()
,
checkTibble()
checkArray(array(1:27, dim = c(3, 3, 3)), d = 3)
checkArray(array(1:27, dim = c(3, 3, 3)), d = 3)
For the definition of “atomic”, see is.atomic
.
Note that 'NULL' is recognized as a valid atomic value, as in R versions up to version 4.3.x. For details, see https://stat.ethz.ch/pipermail/r-devel/2023-September/082892.html.
checkAtomic( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL ) check_atomic( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL ) assertAtomic( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name = vname(x), add = NULL ) assert_atomic( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name = vname(x), add = NULL ) testAtomic( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL ) test_atomic( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL ) expect_atomic( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, info = NULL, label = vname(x) )
checkAtomic( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL ) check_atomic( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL ) assertAtomic( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name = vname(x), add = NULL ) assert_atomic( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name = vname(x), add = NULL ) testAtomic( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL ) test_atomic( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL ) expect_atomic( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, info = NULL, label = vname(x) )
x |
[any] |
any.missing |
[ |
all.missing |
[ |
len |
[ |
min.len |
[ |
max.len |
[ |
unique |
[ |
names |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertAtomic
/assert_atomic
return
x
invisibly, whereas
checkAtomic
/check_atomic
and
testAtomic
/test_atomic
return
TRUE
.
If the check is not successful,
assertAtomic
/assert_atomic
throws an error message,
testAtomic
/test_atomic
returns FALSE
,
and checkAtomic
/check_atomic
return a string with the error message.
The function expect_atomic
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
Other atomicvector:
checkAtomicVector()
,
checkVector()
testAtomic(letters, min.len = 1L, any.missing = FALSE)
testAtomic(letters, min.len = 1L, any.missing = FALSE)
An atomic vector is defined slightly different from specifications in
is.atomic
and is.vector
:
An atomic vector is either logical
, integer
, numeric
,
complex
, character
or raw
and can have any attributes except a
dimension attribute (like matrices).
I.e., a factor
is an atomic vector, but a matrix or NULL
are not.
In short, this is basically equivalent to is.atomic(x) && !is.null(x) && is.null(dim(x))
.
checkAtomicVector( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL ) check_atomic_vector( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL ) assertAtomicVector( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name = vname(x), add = NULL ) assert_atomic_vector( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name = vname(x), add = NULL ) testAtomicVector( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL ) test_atomic_vector( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL ) expect_atomic_vector( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, info = NULL, label = vname(x) )
checkAtomicVector( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL ) check_atomic_vector( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL ) assertAtomicVector( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name = vname(x), add = NULL ) assert_atomic_vector( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name = vname(x), add = NULL ) testAtomicVector( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL ) test_atomic_vector( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL ) expect_atomic_vector( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, info = NULL, label = vname(x) )
x |
[any] |
any.missing |
[ |
all.missing |
[ |
len |
[ |
min.len |
[ |
max.len |
[ |
unique |
[ |
names |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertAtomicVector
/assert_atomic_vector
return
x
invisibly, whereas
checkAtomicVector
/check_atomic_vector
and
testAtomicVector
/test_atomic_vector
return
TRUE
.
If the check is not successful,
assertAtomicVector
/assert_atomic_vector
throws an error message,
testAtomicVector
/test_atomic_vector
returns FALSE
,
and checkAtomicVector
/check_atomic_vector
return a string with the error message.
The function expect_atomic_vector
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
Other atomicvector:
checkAtomic()
,
checkVector()
testAtomicVector(letters, min.len = 1L, any.missing = FALSE)
testAtomicVector(letters, min.len = 1L, any.missing = FALSE)
To check for scalar strings, see checkString
.
checkCharacter( x, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) check_character( x, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) assertCharacter( x, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_character( x, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testCharacter( x, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) test_character( x, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) expect_character( x, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
checkCharacter( x, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) check_character( x, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) assertCharacter( x, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_character( x, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testCharacter( x, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) test_character( x, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) expect_character( x, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
n.chars |
[ |
min.chars |
[ |
max.chars |
[ |
pattern |
[ |
fixed |
[ |
ignore.case |
[ |
any.missing |
[ |
all.missing |
[ |
len |
[ |
min.len |
[ |
max.len |
[ |
unique |
[ |
sorted |
[ |
names |
[ |
typed.missing |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
This function does not distinguish between
NA
, NA_integer_
, NA_real_
, NA_complex_
NA_character_
and NaN
.
Depending on the function prefix:
If the check is successful, the functions
assertCharacter
/assert_character
return
x
invisibly, whereas
checkCharacter
/check_character
and
testCharacter
/test_character
return
TRUE
.
If the check is not successful,
assertCharacter
/assert_character
throws an error message,
testCharacter
/test_character
returns FALSE
,
and checkCharacter
/check_character
return a string with the error message.
The function expect_character
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
testCharacter(letters, min.len = 1, any.missing = FALSE) testCharacter(letters, min.chars = 2) testCharacter("example", pattern = "xa")
testCharacter(letters, min.len = 1, any.missing = FALSE) testCharacter(letters, min.chars = 2) testCharacter("example", pattern = "xa")
Check if an object is an element of a given set
checkChoice(x, choices, null.ok = FALSE, fmatch = FALSE) check_choice(x, choices, null.ok = FALSE, fmatch = FALSE) assertChoice( x, choices, null.ok = FALSE, fmatch = FALSE, .var.name = vname(x), add = NULL ) assert_choice( x, choices, null.ok = FALSE, fmatch = FALSE, .var.name = vname(x), add = NULL ) testChoice(x, choices, null.ok = FALSE, fmatch = FALSE) test_choice(x, choices, null.ok = FALSE, fmatch = FALSE) expect_choice( x, choices, null.ok = FALSE, fmatch = FALSE, info = NULL, label = vname(x) )
checkChoice(x, choices, null.ok = FALSE, fmatch = FALSE) check_choice(x, choices, null.ok = FALSE, fmatch = FALSE) assertChoice( x, choices, null.ok = FALSE, fmatch = FALSE, .var.name = vname(x), add = NULL ) assert_choice( x, choices, null.ok = FALSE, fmatch = FALSE, .var.name = vname(x), add = NULL ) testChoice(x, choices, null.ok = FALSE, fmatch = FALSE) test_choice(x, choices, null.ok = FALSE, fmatch = FALSE) expect_choice( x, choices, null.ok = FALSE, fmatch = FALSE, info = NULL, label = vname(x) )
x |
[any] |
choices |
[ |
null.ok |
[ |
fmatch |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertChoice
/assert_choice
return
x
invisibly, whereas
checkChoice
/check_choice
and
testChoice
/test_choice
return
TRUE
.
If the check is not successful,
assertChoice
/assert_choice
throws an error message,
testChoice
/test_choice
returns FALSE
,
and checkChoice
/check_choice
return a string with the error message.
The function expect_choice
always returns an
expectation
.
The object x
must be of the same type as the set w.r.t. typeof
.
Integers and doubles are both treated as numeric.
Other set:
checkDisjunct()
,
checkPermutation()
,
checkSetEqual()
,
checkSubset()
testChoice("x", letters) # x is not converted before the comparison (except for numerics) testChoice(factor("a"), "a") testChoice(1, "1") testChoice(1, as.integer(1))
testChoice("x", letters) # x is not converted before the comparison (except for numerics) testChoice(factor("a"), "a") testChoice(1, "1") testChoice(1, as.integer(1))
Check the class membership of an argument
checkClass(x, classes, ordered = FALSE, null.ok = FALSE) check_class(x, classes, ordered = FALSE, null.ok = FALSE) assertClass( x, classes, ordered = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_class( x, classes, ordered = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testClass(x, classes, ordered = FALSE, null.ok = FALSE) test_class(x, classes, ordered = FALSE, null.ok = FALSE) expect_class( x, classes, ordered = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
checkClass(x, classes, ordered = FALSE, null.ok = FALSE) check_class(x, classes, ordered = FALSE, null.ok = FALSE) assertClass( x, classes, ordered = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_class( x, classes, ordered = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testClass(x, classes, ordered = FALSE, null.ok = FALSE) test_class(x, classes, ordered = FALSE, null.ok = FALSE) expect_class( x, classes, ordered = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
classes |
[ |
ordered |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertClass
/assert_class
return
x
invisibly, whereas
checkClass
/check_class
and
testClass
/test_class
return
TRUE
.
If the check is not successful,
assertClass
/assert_class
throws an error message,
testClass
/test_class
returns FALSE
,
and checkClass
/check_class
return a string with the error message.
The function expect_class
always returns an
expectation
.
Other attributes:
checkMultiClass()
,
checkNamed()
,
checkNames()
Other classes:
checkMultiClass()
,
checkR6()
# Create an object with classes "foo" and "bar" x = 1 class(x) = c("foo", "bar") # is x of class "foo"? testClass(x, "foo") # is x of class "foo" and "bar"? testClass(x, c("foo", "bar")) # is x of class "foo" or "bar"? ## Not run: assert( checkClass(x, "foo"), checkClass(x, "bar") ) ## End(Not run) # is x most specialized as "bar"? testClass(x, "bar", ordered = TRUE)
# Create an object with classes "foo" and "bar" x = 1 class(x) = c("foo", "bar") # is x of class "foo"? testClass(x, "foo") # is x of class "foo" and "bar"? testClass(x, c("foo", "bar")) # is x of class "foo" or "bar"? ## Not run: assert( checkClass(x, "foo"), checkClass(x, "bar") ) ## End(Not run) # is x most specialized as "bar"? testClass(x, "bar", ordered = TRUE)
Check if an argument is a vector of type complex
checkComplex( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) check_complex( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) assertComplex( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_complex( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testComplex( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) test_complex( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) expect_complex( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
checkComplex( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) check_complex( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) assertComplex( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_complex( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testComplex( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) test_complex( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) expect_complex( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
any.missing |
[ |
all.missing |
[ |
len |
[ |
min.len |
[ |
max.len |
[ |
unique |
[ |
names |
[ |
typed.missing |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
This function does not distinguish between
NA
, NA_integer_
, NA_real_
, NA_complex_
NA_character_
and NaN
.
Depending on the function prefix:
If the check is successful, the functions
assertComplex
/assert_complex
return
x
invisibly, whereas
checkComplex
/check_complex
and
testComplex
/test_complex
return
TRUE
.
If the check is not successful,
assertComplex
/assert_complex
throws an error message,
testComplex
/test_complex
returns FALSE
,
and checkComplex
/check_complex
return a string with the error message.
The function expect_complex
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
testComplex(1) testComplex(1+1i)
testComplex(1) testComplex(1+1i)
A count is defined as non-negative integerish value.
checkCount( x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), null.ok = FALSE ) check_count( x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), null.ok = FALSE ) assertCount( x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), null.ok = FALSE, coerce = FALSE, .var.name = vname(x), add = NULL ) assert_count( x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), null.ok = FALSE, coerce = FALSE, .var.name = vname(x), add = NULL ) testCount( x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), null.ok = FALSE ) test_count( x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), null.ok = FALSE ) expect_count( x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), null.ok = FALSE, info = NULL, label = vname(x) )
checkCount( x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), null.ok = FALSE ) check_count( x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), null.ok = FALSE ) assertCount( x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), null.ok = FALSE, coerce = FALSE, .var.name = vname(x), add = NULL ) assert_count( x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), null.ok = FALSE, coerce = FALSE, .var.name = vname(x), add = NULL ) testCount( x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), null.ok = FALSE ) test_count( x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), null.ok = FALSE ) expect_count( x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
na.ok |
[ |
positive |
[ |
tol |
[ |
null.ok |
[ |
coerce |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
This function does not distinguish between
NA
, NA_integer_
, NA_real_
, NA_complex_
NA_character_
and NaN
.
Depending on the function prefix:
If the check is successful, the functions
assertCount
/assert_count
return
x
invisibly, whereas
checkCount
/check_count
and
testCount
/test_count
return
TRUE
.
If the check is not successful,
assertCount
/assert_count
throws an error message,
testCount
/test_count
returns FALSE
,
and checkCount
/check_count
return a string with the error message.
The function expect_count
always returns an
expectation
.
To perform an assertion and then convert to integer, use asCount
.
assertCount
will not convert numerics to integer.
Other scalars:
checkFlag()
,
checkInt()
,
checkNumber()
,
checkScalar()
,
checkScalarNA()
,
checkString()
testCount(1) testCount(-1)
testCount(1) testCount(-1)
Check if an argument is a data frame
checkDataFrame( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) check_data_frame( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) assertDataFrame( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_data_frame( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testDataFrame( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) test_data_frame( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) expect_data_frame( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
checkDataFrame( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) check_data_frame( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) assertDataFrame( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_data_frame( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testDataFrame( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) test_data_frame( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) expect_data_frame( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
types |
[ |
any.missing |
[ |
all.missing |
[ |
min.rows |
[ |
max.rows |
[ |
min.cols |
[ |
max.cols |
[ |
nrows |
[ |
ncols |
[ |
row.names |
[ |
col.names |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertDataFrame
/assert_data_frame
return
x
invisibly, whereas
checkDataFrame
/check_data_frame
and
testDataFrame
/test_data_frame
return
TRUE
.
If the check is not successful,
assertDataFrame
/assert_data_frame
throws an error message,
testDataFrame
/test_data_frame
returns FALSE
,
and checkDataFrame
/check_data_frame
return a string with the error message.
The function expect_data_frame
always returns an
expectation
.
Other compound:
checkArray()
,
checkDataTable()
,
checkMatrix()
,
checkTibble()
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
testDataFrame(iris) testDataFrame(iris, types = c("numeric", "factor"), min.rows = 1, col.names = "named")
testDataFrame(iris) testDataFrame(iris, types = c("numeric", "factor"), min.rows = 1, col.names = "named")
Check if an argument is a data table
checkDataTable( x, key = NULL, index = NULL, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) check_data_table( x, key = NULL, index = NULL, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) assertDataTable( x, key = NULL, index = NULL, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_data_table( x, key = NULL, index = NULL, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testDataTable( x, key = NULL, index = NULL, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) test_data_table( x, key = NULL, index = NULL, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) expect_data_table( x, key = NULL, index = NULL, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
checkDataTable( x, key = NULL, index = NULL, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) check_data_table( x, key = NULL, index = NULL, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) assertDataTable( x, key = NULL, index = NULL, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_data_table( x, key = NULL, index = NULL, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testDataTable( x, key = NULL, index = NULL, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) test_data_table( x, key = NULL, index = NULL, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) expect_data_table( x, key = NULL, index = NULL, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
key |
[ |
index |
[ |
types |
[ |
any.missing |
[ |
all.missing |
[ |
min.rows |
[ |
max.rows |
[ |
min.cols |
[ |
max.cols |
[ |
nrows |
[ |
ncols |
[ |
row.names |
[ |
col.names |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertDataTable
/assert_data_table
return
x
invisibly, whereas
checkDataTable
/check_data_table
and
testDataTable
/test_data_table
return
TRUE
.
If the check is not successful,
assertDataTable
/assert_data_table
throws an error message,
testDataTable
/test_data_table
returns FALSE
,
and checkDataTable
/check_data_table
return a string with the error message.
The function expect_data_table
always returns an
expectation
.
Other compound:
checkArray()
,
checkDataFrame()
,
checkMatrix()
,
checkTibble()
library(data.table) dt = as.data.table(iris) setkeyv(dt, "Species") setkeyv(dt, "Sepal.Length", physical = FALSE) testDataTable(dt) testDataTable(dt, key = "Species", index = "Sepal.Length", any.missing = FALSE)
library(data.table) dt = as.data.table(iris) setkeyv(dt, "Species") setkeyv(dt, "Sepal.Length", physical = FALSE) testDataTable(dt) testDataTable(dt, key = "Species", index = "Sepal.Length", any.missing = FALSE)
Checks that an object is of class Date
.
checkDate( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, null.ok = FALSE ) check_date( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, null.ok = FALSE ) assertDate( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_date( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testDate( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, null.ok = FALSE ) test_date( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, null.ok = FALSE ) expect_date( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
checkDate( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, null.ok = FALSE ) check_date( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, null.ok = FALSE ) assertDate( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_date( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testDate( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, null.ok = FALSE ) test_date( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, null.ok = FALSE ) expect_date( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
lower |
[ |
upper |
[ |
any.missing |
[ |
all.missing |
[ |
len |
[ |
min.len |
[ |
max.len |
[ |
unique |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertAtomic
/assert_atomic
return
x
invisibly, whereas
checkAtomic
/check_atomic
and
testAtomic
/test_atomic
return
TRUE
.
If the check is not successful,
assertAtomic
/assert_atomic
throws an error message,
testAtomic
/test_atomic
returns FALSE
,
and checkAtomic
/check_atomic
return a string with the error message.
The function expect_atomic
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
Check for existence and access rights of directories
checkDirectoryExists(x, access = "") check_directory_exists(x, access = "") assertDirectoryExists(x, access = "", .var.name = vname(x), add = NULL) assert_directory_exists(x, access = "", .var.name = vname(x), add = NULL) testDirectoryExists(x, access = "") test_directory_exists(x, access = "") expect_directory_exists(x, access = "", info = NULL, label = vname(x)) checkDirectory(x, access = "") assertDirectory(x, access = "", .var.name = vname(x), add = NULL) assert_directory(x, access = "", .var.name = vname(x), add = NULL) testDirectory(x, access = "") test_directory(x, access = "") expect_directory(x, access = "", info = NULL, label = vname(x))
checkDirectoryExists(x, access = "") check_directory_exists(x, access = "") assertDirectoryExists(x, access = "", .var.name = vname(x), add = NULL) assert_directory_exists(x, access = "", .var.name = vname(x), add = NULL) testDirectoryExists(x, access = "") test_directory_exists(x, access = "") expect_directory_exists(x, access = "", info = NULL, label = vname(x)) checkDirectory(x, access = "") assertDirectory(x, access = "", .var.name = vname(x), add = NULL) assert_directory(x, access = "", .var.name = vname(x), add = NULL) testDirectory(x, access = "") test_directory(x, access = "") expect_directory(x, access = "", info = NULL, label = vname(x))
x |
[any] |
access |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertDirectoryExists
/assert_directory_exists
return
x
invisibly, whereas
checkDirectoryExists
/check_directory_exists
and
testDirectoryExists
/test_directory_exists
return
TRUE
.
If the check is not successful,
assertDirectoryExists
/assert_directory_exists
throws an error message,
testDirectoryExists
/test_directory_exists
returns FALSE
,
and checkDirectoryExists
/check_directory_exists
return a string with the error message.
The function expect_directory_exists
always returns an
expectation
.
The functions without the suffix “exists” are deprecated and will be removed from the package in a future version due to name clashes.
Other filesystem:
checkAccess()
,
checkFileExists()
,
checkPathForOutput()
# Is R's home directory readable? testDirectory(R.home(), "r") # Is R's home directory readable and writable? testDirectory(R.home(), "rw")
# Is R's home directory readable? testDirectory(R.home(), "r") # Is R's home directory readable and writable? testDirectory(R.home(), "rw")
Check if an argument is disjunct from a given set
checkDisjunct(x, y, fmatch = FALSE) check_disjunct(x, y, fmatch = FALSE) assertDisjunct(x, y, fmatch = FALSE, .var.name = vname(x), add = NULL) assert_disjunct(x, y, fmatch = FALSE, .var.name = vname(x), add = NULL) testDisjunct(x, y, fmatch = FALSE) test_disjunct(x, y, fmatch = FALSE) expect_disjunct(x, y, fmatch = FALSE, info = NULL, label = vname(x))
checkDisjunct(x, y, fmatch = FALSE) check_disjunct(x, y, fmatch = FALSE) assertDisjunct(x, y, fmatch = FALSE, .var.name = vname(x), add = NULL) assert_disjunct(x, y, fmatch = FALSE, .var.name = vname(x), add = NULL) testDisjunct(x, y, fmatch = FALSE) test_disjunct(x, y, fmatch = FALSE) expect_disjunct(x, y, fmatch = FALSE, info = NULL, label = vname(x))
x |
[any] |
y |
[ |
fmatch |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertDisjunct
/assert_disjunct
return
x
invisibly, whereas
checkDisjunct
/check_disjunct
and
testDisjunct
/test_disjunct
return
TRUE
.
If the check is not successful,
assertDisjunct
/assert_disjunct
throws an error message,
testDisjunct
/test_disjunct
returns FALSE
,
and checkDisjunct
/check_disjunct
return a string with the error message.
The function expect_disjunct
always returns an
expectation
.
The object x
must be of the same type as the set w.r.t. typeof
.
Integers and doubles are both treated as numeric.
Other set:
checkChoice()
,
checkPermutation()
,
checkSetEqual()
,
checkSubset()
testDisjunct(1L, letters) testDisjunct(c("a", "z"), letters) # x is not converted before the comparison (except for numerics) testDisjunct(factor("a"), "a") testDisjunct(1, "1") testDisjunct(1, as.integer(1))
testDisjunct(1L, letters) testDisjunct(c("a", "z"), letters) # x is not converted before the comparison (except for numerics) testDisjunct(factor("a"), "a") testDisjunct(1, "1") testDisjunct(1, as.integer(1))
Check that an argument is a vector of type double
checkDouble( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) check_double( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) assertDouble( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_double( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testDouble( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) test_double( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) expect_double( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
checkDouble( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) check_double( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) assertDouble( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_double( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testDouble( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) test_double( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) expect_double( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
lower |
[ |
upper |
[ |
finite |
[ |
any.missing |
[ |
all.missing |
[ |
len |
[ |
min.len |
[ |
max.len |
[ |
unique |
[ |
sorted |
[ |
names |
[ |
typed.missing |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
This function does not distinguish between
NA
, NA_integer_
, NA_real_
, NA_complex_
NA_character_
and NaN
.
Depending on the function prefix:
If the check is successful, the functions
assertDouble
/assert_double
return
x
invisibly, whereas
checkDouble
/check_double
and
testDouble
/test_double
return
TRUE
.
If the check is not successful,
assertDouble
/assert_double
throws an error message,
testDouble
/test_double
returns FALSE
,
and checkDouble
/check_double
return a string with the error message.
The function expect_double
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
testDouble(1) testDouble(1L) testDouble(1, min.len = 1, lower = 0)
testDouble(1) testDouble(1L) testDouble(1, min.len = 1, lower = 0)
Check if an argument is an environment
checkEnvironment(x, contains = character(0L), null.ok = FALSE) check_environment(x, contains = character(0L), null.ok = FALSE) assertEnvironment( x, contains = character(0L), null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_environment( x, contains = character(0L), null.ok = FALSE, .var.name = vname(x), add = NULL ) testEnvironment(x, contains = character(0L), null.ok = FALSE) test_environment(x, contains = character(0L), null.ok = FALSE) expect_environment( x, contains = character(0L), null.ok = FALSE, info = NULL, label = vname(x) )
checkEnvironment(x, contains = character(0L), null.ok = FALSE) check_environment(x, contains = character(0L), null.ok = FALSE) assertEnvironment( x, contains = character(0L), null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_environment( x, contains = character(0L), null.ok = FALSE, .var.name = vname(x), add = NULL ) testEnvironment(x, contains = character(0L), null.ok = FALSE) test_environment(x, contains = character(0L), null.ok = FALSE) expect_environment( x, contains = character(0L), null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
contains |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertEnvironment
/assert_environment
return
x
invisibly, whereas
checkEnvironment
/check_environment
and
testEnvironment
/test_environment
return
TRUE
.
If the check is not successful,
assertEnvironment
/assert_environment
throws an error message,
testEnvironment
/test_environment
returns FALSE
,
and checkEnvironment
/check_environment
return a string with the error message.
The function expect_environment
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
ee = as.environment(list(a = 1)) testEnvironment(ee) testEnvironment(ee, contains = "a")
ee = as.environment(list(a = 1)) testEnvironment(ee) testEnvironment(ee, contains = "a")
Check if an argument is a factor
checkFactor( x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) check_factor( x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) assertFactor( x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_factor( x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testFactor( x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) test_factor( x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) expect_factor( x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
checkFactor( x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) check_factor( x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) assertFactor( x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_factor( x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testFactor( x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) test_factor( x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) expect_factor( x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
levels |
[ |
ordered |
[ |
empty.levels.ok |
[ |
any.missing |
[ |
all.missing |
[ |
len |
[ |
min.len |
[ |
max.len |
[ |
n.levels |
[ |
min.levels |
[ |
max.levels |
[ |
unique |
[ |
names |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertFactor
/assert_factor
return
x
invisibly, whereas
checkFactor
/check_factor
and
testFactor
/test_factor
return
TRUE
.
If the check is not successful,
assertFactor
/assert_factor
throws an error message,
testFactor
/test_factor
returns FALSE
,
and checkFactor
/check_factor
return a string with the error message.
The function expect_factor
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
x = factor("a", levels = c("a", "b")) testFactor(x) testFactor(x, empty.levels.ok = FALSE)
x = factor("a", levels = c("a", "b")) testFactor(x) testFactor(x, empty.levels.ok = FALSE)
Simply checks if an argument is FALSE
.
checkFALSE(x, na.ok = FALSE) check_false(x, na.ok = FALSE) assertFALSE(x, na.ok = FALSE, .var.name = vname(x), add = NULL) assert_false(x, na.ok = FALSE, .var.name = vname(x), add = NULL) testFALSE(x, na.ok = FALSE) test_false(x, na.ok = FALSE)
checkFALSE(x, na.ok = FALSE) check_false(x, na.ok = FALSE) assertFALSE(x, na.ok = FALSE, .var.name = vname(x), add = NULL) assert_false(x, na.ok = FALSE, .var.name = vname(x), add = NULL) testFALSE(x, na.ok = FALSE) test_false(x, na.ok = FALSE)
x |
[any] |
na.ok |
[ |
.var.name |
[ |
add |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertFALSE.
/assert_false.
return
x
invisibly, whereas
checkFALSE.
/check_false.
and
testFALSE.
/test_false.
return
TRUE
.
If the check is not successful,
assertFALSE.
/assert_false.
throws an error message,
testFALSE.
/test_false.
returns FALSE
,
and checkFALSE.
/check_false.
return a string with the error message.
The function expect_false.
always returns an
expectation
.
testFALSE(FALSE) testFALSE(TRUE)
testFALSE(FALSE) testFALSE(TRUE)
Check existence and access rights of files
checkFileExists(x, access = "", extension = NULL) check_file_exists(x, access = "", extension = NULL) assertFileExists( x, access = "", extension = NULL, .var.name = vname(x), add = NULL ) assert_file_exists( x, access = "", extension = NULL, .var.name = vname(x), add = NULL ) testFileExists(x, access = "", extension = NULL) test_file_exists(x, access = "", extension = NULL) expect_file_exists( x, access = "", extension = NULL, info = NULL, label = vname(x) ) checkFile(x, access = "", extension = NULL) assertFile(x, access = "", extension = NULL, .var.name = vname(x), add = NULL) assert_file(x, access = "", extension = NULL, .var.name = vname(x), add = NULL) testFile(x, access = "", extension = NULL) expect_file(x, access = "", extension = NULL, info = NULL, label = vname(x))
checkFileExists(x, access = "", extension = NULL) check_file_exists(x, access = "", extension = NULL) assertFileExists( x, access = "", extension = NULL, .var.name = vname(x), add = NULL ) assert_file_exists( x, access = "", extension = NULL, .var.name = vname(x), add = NULL ) testFileExists(x, access = "", extension = NULL) test_file_exists(x, access = "", extension = NULL) expect_file_exists( x, access = "", extension = NULL, info = NULL, label = vname(x) ) checkFile(x, access = "", extension = NULL) assertFile(x, access = "", extension = NULL, .var.name = vname(x), add = NULL) assert_file(x, access = "", extension = NULL, .var.name = vname(x), add = NULL) testFile(x, access = "", extension = NULL) expect_file(x, access = "", extension = NULL, info = NULL, label = vname(x))
x |
[any] |
access |
[ |
extension |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertFileExists
/assert_file_exists
return
x
invisibly, whereas
checkFileExists
/check_file_exists
and
testFileExists
/test_file_exists
return
TRUE
.
If the check is not successful,
assertFileExists
/assert_file_exists
throws an error message,
testFileExists
/test_file_exists
returns FALSE
,
and checkFileExists
/check_file_exists
return a string with the error message.
The function expect_file_exists
always returns an
expectation
.
The functions without the suffix “exists” are deprecated and will be removed
from the package in a future version due to name clashes.
test_file
has been unexported already.
Other filesystem:
checkAccess()
,
checkDirectoryExists()
,
checkPathForOutput()
# Check if R's COPYING file is readable testFileExists(file.path(R.home(), "COPYING"), access = "r") # Check if R's COPYING file is readable and writable testFileExists(file.path(R.home(), "COPYING"), access = "rw")
# Check if R's COPYING file is readable testFileExists(file.path(R.home(), "COPYING"), access = "r") # Check if R's COPYING file is readable and writable testFileExists(file.path(R.home(), "COPYING"), access = "rw")
A flag is defined as single logical value.
checkFlag(x, na.ok = FALSE, null.ok = FALSE) check_flag(x, na.ok = FALSE, null.ok = FALSE) assertFlag(x, na.ok = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL) assert_flag( x, na.ok = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testFlag(x, na.ok = FALSE, null.ok = FALSE) test_flag(x, na.ok = FALSE, null.ok = FALSE) expect_flag(x, na.ok = FALSE, null.ok = FALSE, info = NULL, label = vname(x))
checkFlag(x, na.ok = FALSE, null.ok = FALSE) check_flag(x, na.ok = FALSE, null.ok = FALSE) assertFlag(x, na.ok = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL) assert_flag( x, na.ok = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testFlag(x, na.ok = FALSE, null.ok = FALSE) test_flag(x, na.ok = FALSE, null.ok = FALSE) expect_flag(x, na.ok = FALSE, null.ok = FALSE, info = NULL, label = vname(x))
x |
[any] |
na.ok |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
This function does not distinguish between
NA
, NA_integer_
, NA_real_
, NA_complex_
NA_character_
and NaN
.
Depending on the function prefix:
If the check is successful, the functions
assertFlag
/assert_flag
return
x
invisibly, whereas
checkFlag
/check_flag
and
testFlag
/test_flag
return
TRUE
.
If the check is not successful,
assertFlag
/assert_flag
throws an error message,
testFlag
/test_flag
returns FALSE
,
and checkFlag
/check_flag
return a string with the error message.
The function expect_flag
always returns an
expectation
.
Other scalars:
checkCount()
,
checkInt()
,
checkNumber()
,
checkScalar()
,
checkScalarNA()
,
checkString()
testFlag(TRUE) testFlag(1)
testFlag(TRUE) testFlag(1)
Check if an argument is a formula
checkFormula(x, null.ok = FALSE) check_formula(x, null.ok = FALSE) assertFormula(x, null.ok = FALSE, .var.name = vname(x), add = NULL) assert_formula(x, null.ok = FALSE, .var.name = vname(x), add = NULL) testFormula(x, null.ok = FALSE) test_formula(x, null.ok = FALSE) expect_formula(x, null.ok = FALSE, info = NULL, label = vname(x))
checkFormula(x, null.ok = FALSE) check_formula(x, null.ok = FALSE) assertFormula(x, null.ok = FALSE, .var.name = vname(x), add = NULL) assert_formula(x, null.ok = FALSE, .var.name = vname(x), add = NULL) testFormula(x, null.ok = FALSE) test_formula(x, null.ok = FALSE) expect_formula(x, null.ok = FALSE, info = NULL, label = vname(x))
x |
[any] |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertFormula
/assert_formula
return
x
invisibly, whereas
checkFormula
/check_formula
and
testFormula
/test_formula
return
TRUE
.
If the check is not successful,
assertFormula
/assert_formula
throws an error message,
testFormula
/test_formula
returns FALSE
,
and checkFormula
/check_formula
return a string with the error message.
The function expect_formula
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
f = Species ~ Sepal.Length + Sepal.Width checkFormula(f)
f = Species ~ Sepal.Length + Sepal.Width checkFormula(f)
Check if an argument is a function
checkFunction(x, args = NULL, ordered = FALSE, nargs = NULL, null.ok = FALSE) check_function(x, args = NULL, ordered = FALSE, nargs = NULL, null.ok = FALSE) assertFunction( x, args = NULL, ordered = FALSE, nargs = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_function( x, args = NULL, ordered = FALSE, nargs = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testFunction(x, args = NULL, ordered = FALSE, nargs = NULL, null.ok = FALSE) test_function(x, args = NULL, ordered = FALSE, nargs = NULL, null.ok = FALSE) expect_function( x, args = NULL, ordered = FALSE, nargs = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
checkFunction(x, args = NULL, ordered = FALSE, nargs = NULL, null.ok = FALSE) check_function(x, args = NULL, ordered = FALSE, nargs = NULL, null.ok = FALSE) assertFunction( x, args = NULL, ordered = FALSE, nargs = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_function( x, args = NULL, ordered = FALSE, nargs = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testFunction(x, args = NULL, ordered = FALSE, nargs = NULL, null.ok = FALSE) test_function(x, args = NULL, ordered = FALSE, nargs = NULL, null.ok = FALSE) expect_function( x, args = NULL, ordered = FALSE, nargs = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
args |
[ |
ordered |
[ |
nargs |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertFunction
/assert_function
return
x
invisibly, whereas
checkFunction
/check_function
and
testFunction
/test_function
return
TRUE
.
If the check is not successful,
assertFunction
/assert_function
throws an error message,
testFunction
/test_function
returns FALSE
,
and checkFunction
/check_function
return a string with the error message.
The function expect_function
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
testFunction(mean) testFunction(mean, args = "x")
testFunction(mean) testFunction(mean, args = "x")
Check if an argument is a single integerish value
checkInt( x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), null.ok = FALSE ) check_int( x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), null.ok = FALSE ) assertInt( x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), null.ok = FALSE, coerce = FALSE, .var.name = vname(x), add = NULL ) assert_int( x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), null.ok = FALSE, coerce = FALSE, .var.name = vname(x), add = NULL ) testInt( x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), null.ok = FALSE ) test_int( x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), null.ok = FALSE ) expect_int( x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), null.ok = FALSE, info = NULL, label = vname(x) )
checkInt( x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), null.ok = FALSE ) check_int( x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), null.ok = FALSE ) assertInt( x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), null.ok = FALSE, coerce = FALSE, .var.name = vname(x), add = NULL ) assert_int( x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), null.ok = FALSE, coerce = FALSE, .var.name = vname(x), add = NULL ) testInt( x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), null.ok = FALSE ) test_int( x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), null.ok = FALSE ) expect_int( x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
na.ok |
[ |
lower |
[ |
upper |
[ |
tol |
[ |
null.ok |
[ |
coerce |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
This function does not distinguish between
NA
, NA_integer_
, NA_real_
, NA_complex_
NA_character_
and NaN
.
Depending on the function prefix:
If the check is successful, the functions
assertInt
/assert_int
return
x
invisibly, whereas
checkInt
/check_int
and
testInt
/test_int
return
TRUE
.
If the check is not successful,
assertInt
/assert_int
throws an error message,
testInt
/test_int
returns FALSE
,
and checkInt
/check_int
return a string with the error message.
The function expect_int
always returns an
expectation
.
To perform an assertion and then convert to integer, use asInt
.
assertInt
will not convert numerics to integer.
Other scalars:
checkCount()
,
checkFlag()
,
checkNumber()
,
checkScalar()
,
checkScalarNA()
,
checkString()
testInt(1) testInt(-1, lower = 0)
testInt(1) testInt(-1, lower = 0)
Check if an argument is vector of type integer
checkInteger( x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) check_integer( x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) assertInteger( x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_integer( x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testInteger( x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) test_integer( x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) expect_integer( x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
checkInteger( x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) check_integer( x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) assertInteger( x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_integer( x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testInteger( x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) test_integer( x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) expect_integer( x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
lower |
[ |
upper |
[ |
any.missing |
[ |
all.missing |
[ |
len |
[ |
min.len |
[ |
max.len |
[ |
unique |
[ |
sorted |
[ |
names |
[ |
typed.missing |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
This function does not distinguish between
NA
, NA_integer_
, NA_real_
, NA_complex_
NA_character_
and NaN
.
Depending on the function prefix:
If the check is successful, the functions
assertInteger
/assert_integer
return
x
invisibly, whereas
checkInteger
/check_integer
and
testInteger
/test_integer
return
TRUE
.
If the check is not successful,
assertInteger
/assert_integer
throws an error message,
testInteger
/test_integer
returns FALSE
,
and checkInteger
/check_integer
return a string with the error message.
The function expect_integer
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
testInteger(1L) testInteger(1.) testInteger(1:2, lower = 1, upper = 2, any.missing = FALSE)
testInteger(1L) testInteger(1.) testInteger(1:2, lower = 1, upper = 2, any.missing = FALSE)
An integerish value is defined as value safely convertible to integer. This includes integers and numeric values which sufficiently close to an integer w.r.t. a numeric tolerance 'tol'.
checkIntegerish( x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) check_integerish( x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) assertIntegerish( x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, coerce = FALSE, .var.name = vname(x), add = NULL ) assert_integerish( x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, coerce = FALSE, .var.name = vname(x), add = NULL ) testIntegerish( x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) test_integerish( x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) expect_integerish( x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
checkIntegerish( x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) check_integerish( x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) assertIntegerish( x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, coerce = FALSE, .var.name = vname(x), add = NULL ) assert_integerish( x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, coerce = FALSE, .var.name = vname(x), add = NULL ) testIntegerish( x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) test_integerish( x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) expect_integerish( x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
tol |
[ |
lower |
[ |
upper |
[ |
any.missing |
[ |
all.missing |
[ |
len |
[ |
min.len |
[ |
max.len |
[ |
unique |
[ |
sorted |
[ |
names |
[ |
typed.missing |
[ |
null.ok |
[ |
coerce |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
This function does not distinguish between
NA
, NA_integer_
, NA_real_
, NA_complex_
NA_character_
and NaN
.
Depending on the function prefix:
If the check is successful, the functions
assertIntegerish
/assert_integerish
return
x
invisibly, whereas
checkIntegerish
/check_integerish
and
testIntegerish
/test_integerish
return
TRUE
.
If the check is not successful,
assertIntegerish
/assert_integerish
throws an error message,
testIntegerish
/test_integerish
returns FALSE
,
and checkIntegerish
/check_integerish
return a string with the error message.
The function expect_integerish
always returns an
expectation
.
To convert from integerish to integer, use asInteger
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
testIntegerish(1L) testIntegerish(1.) testIntegerish(1:2, lower = 1L, upper = 2L, any.missing = FALSE)
testIntegerish(1L) testIntegerish(1.) testIntegerish(1:2, lower = 1L, upper = 2L, any.missing = FALSE)
Check if an argument is a list
checkList( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) check_list( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) assertList( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_list( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testList( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) test_list( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) expect_list( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
checkList( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) check_list( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) assertList( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_list( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testList( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) test_list( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) expect_list( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
types |
[ |
any.missing |
[ |
all.missing |
[ |
len |
[ |
min.len |
[ |
max.len |
[ |
unique |
[ |
names |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertList
/assert_list
return
x
invisibly, whereas
checkList
/check_list
and
testList
/test_list
return
TRUE
.
If the check is not successful,
assertList
/assert_list
throws an error message,
testList
/test_list
returns FALSE
,
and checkList
/check_list
return a string with the error message.
The function expect_list
always returns an
expectation
.
Contrary to R's is.list
, objects of type data.frame
and pairlist
are not recognized as list.
Missingness is defined here as elements of the list being NULL
, analogously to anyMissing
.
The test for uniqueness does differentiate between the different NA types which are built-in in R.
This is required to be consistent with unique
while checking
scalar missing values. Also see the example.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
testList(list()) testList(as.list(iris), types = c("numeric", "factor")) # Missingness testList(list(1, NA), any.missing = FALSE) testList(list(1, NULL), any.missing = FALSE) # Uniqueness differentiates between different NA types: testList(list(NA, NA), unique = TRUE) testList(list(NA, NA_real_), unique = TRUE)
testList(list()) testList(as.list(iris), types = c("numeric", "factor")) # Missingness testList(list(1, NA), any.missing = FALSE) testList(list(1, NULL), any.missing = FALSE) # Uniqueness differentiates between different NA types: testList(list(NA, NA), unique = TRUE) testList(list(NA, NA_real_), unique = TRUE)
Check if an argument is a vector of type logical
checkLogical( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) check_logical( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) assertLogical( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_logical( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testLogical( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) test_logical( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) expect_logical( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
checkLogical( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) check_logical( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) assertLogical( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_logical( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testLogical( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) test_logical( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) expect_logical( x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
any.missing |
[ |
all.missing |
[ |
len |
[ |
min.len |
[ |
max.len |
[ |
unique |
[ |
names |
[ |
typed.missing |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
This function does not distinguish between
NA
, NA_integer_
, NA_real_
, NA_complex_
NA_character_
and NaN
.
Depending on the function prefix:
If the check is successful, the functions
assertLogical
/assert_logical
return
x
invisibly, whereas
checkLogical
/check_logical
and
testLogical
/test_logical
return
TRUE
.
If the check is not successful,
assertLogical
/assert_logical
throws an error message,
testLogical
/test_logical
returns FALSE
,
and checkLogical
/check_logical
return a string with the error message.
The function expect_logical
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
testLogical(TRUE) testLogical(TRUE, min.len = 1)
testLogical(TRUE) testLogical(TRUE, min.len = 1)
Check if an argument is a matrix
checkMatrix( x, mode = NULL, any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) check_matrix( x, mode = NULL, any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) assertMatrix( x, mode = NULL, any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_matrix( x, mode = NULL, any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testMatrix( x, mode = NULL, any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) test_matrix( x, mode = NULL, any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) expect_matrix( x, mode = NULL, any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
checkMatrix( x, mode = NULL, any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) check_matrix( x, mode = NULL, any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) assertMatrix( x, mode = NULL, any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_matrix( x, mode = NULL, any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testMatrix( x, mode = NULL, any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) test_matrix( x, mode = NULL, any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) expect_matrix( x, mode = NULL, any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
mode |
[ |
any.missing |
[ |
all.missing |
[ |
min.rows |
[ |
max.rows |
[ |
min.cols |
[ |
max.cols |
[ |
nrows |
[ |
ncols |
[ |
row.names |
[ |
col.names |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertMatrix
/assert_matrix
return
x
invisibly, whereas
checkMatrix
/check_matrix
and
testMatrix
/test_matrix
return
TRUE
.
If the check is not successful,
assertMatrix
/assert_matrix
throws an error message,
testMatrix
/test_matrix
returns FALSE
,
and checkMatrix
/check_matrix
return a string with the error message.
The function expect_matrix
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
Other compound:
checkArray()
,
checkDataFrame()
,
checkDataTable()
,
checkTibble()
x = matrix(1:9, 3) colnames(x) = letters[1:3] testMatrix(x, nrows = 3, min.cols = 1, col.names = "named")
x = matrix(1:9, 3) colnames(x) = letters[1:3] testMatrix(x, nrows = 3, min.cols = 1, col.names = "named")
Check the class membership of an argument
checkMultiClass(x, classes, null.ok = FALSE) check_multi_class(x, classes, null.ok = FALSE) assertMultiClass(x, classes, null.ok = FALSE, .var.name = vname(x), add = NULL) assert_multi_class( x, classes, null.ok = FALSE, .var.name = vname(x), add = NULL ) testMultiClass(x, classes, null.ok = FALSE) test_multi_class(x, classes, null.ok = FALSE) expect_multi_class(x, classes, null.ok = FALSE, info = NULL, label = vname(x))
checkMultiClass(x, classes, null.ok = FALSE) check_multi_class(x, classes, null.ok = FALSE) assertMultiClass(x, classes, null.ok = FALSE, .var.name = vname(x), add = NULL) assert_multi_class( x, classes, null.ok = FALSE, .var.name = vname(x), add = NULL ) testMultiClass(x, classes, null.ok = FALSE) test_multi_class(x, classes, null.ok = FALSE) expect_multi_class(x, classes, null.ok = FALSE, info = NULL, label = vname(x))
x |
[any] |
classes |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertMultiClass
/assert_multi_class
return
x
invisibly, whereas
checkMultiClass
/check_multi_class
and
testMultiClass
/test_multi_class
return
TRUE
.
If the check is not successful,
assertMultiClass
/assert_multi_class
throws an error message,
testMultiClass
/test_multi_class
returns FALSE
,
and checkMultiClass
/check_multi_class
return a string with the error message.
The function expect_multi_class
always returns an
expectation
.
Other attributes:
checkClass()
,
checkNamed()
,
checkNames()
Other classes:
checkClass()
,
checkR6()
x = 1 class(x) = "bar" checkMultiClass(x, c("foo", "bar")) checkMultiClass(x, c("foo", "foobar"))
x = 1 class(x) = "bar" checkMultiClass(x, c("foo", "bar")) checkMultiClass(x, c("foo", "foobar"))
Check if an argument is named
checkNamed(x, type = "named") check_named(x, type = "named") assertNamed(x, type = "named", .var.name = vname(x), add = NULL) assert_named(x, type = "named", .var.name = vname(x), add = NULL) testNamed(x, type = "named") test_named(x, type = "named")
checkNamed(x, type = "named") check_named(x, type = "named") assertNamed(x, type = "named", .var.name = vname(x), add = NULL) assert_named(x, type = "named", .var.name = vname(x), add = NULL) testNamed(x, type = "named") test_named(x, type = "named")
x |
[any] |
type |
[character(1)] |
.var.name |
[ |
add |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertNamed
/assert_named
return
x
invisibly, whereas
checkNamed
/check_named
and
testNamed
/test_named
return
TRUE
.
If the check is not successful,
assertNamed
/assert_named
throws an error message,
testNamed
/test_named
returns FALSE
,
and checkNamed
/check_named
return a string with the error message.
The function expect_named
always returns an
expectation
.
These function are deprecated and will be removed in a future version.
Please use checkNames
instead.
Other attributes:
checkClass()
,
checkMultiClass()
,
checkNames()
x = 1:3 testNamed(x, "unnamed") names(x) = letters[1:3] testNamed(x, "unique")
x = 1:3 testNamed(x, "unnamed") names(x) = letters[1:3] testNamed(x, "unique")
Performs various checks on character vectors, usually names.
checkNames( x, type = "named", subset.of = NULL, must.include = NULL, permutation.of = NULL, identical.to = NULL, disjunct.from = NULL, what = "names" ) check_names( x, type = "named", subset.of = NULL, must.include = NULL, permutation.of = NULL, identical.to = NULL, disjunct.from = NULL, what = "names" ) assertNames( x, type = "named", subset.of = NULL, must.include = NULL, permutation.of = NULL, identical.to = NULL, disjunct.from = NULL, what = "names", .var.name = vname(x), add = NULL ) assert_names( x, type = "named", subset.of = NULL, must.include = NULL, permutation.of = NULL, identical.to = NULL, disjunct.from = NULL, what = "names", .var.name = vname(x), add = NULL ) testNames( x, type = "named", subset.of = NULL, must.include = NULL, permutation.of = NULL, identical.to = NULL, disjunct.from = NULL, what = "names" ) test_names( x, type = "named", subset.of = NULL, must.include = NULL, permutation.of = NULL, identical.to = NULL, disjunct.from = NULL, what = "names" ) expect_names( x, type = "named", subset.of = NULL, must.include = NULL, permutation.of = NULL, identical.to = NULL, disjunct.from = NULL, what = "names", info = NULL, label = vname(x) )
checkNames( x, type = "named", subset.of = NULL, must.include = NULL, permutation.of = NULL, identical.to = NULL, disjunct.from = NULL, what = "names" ) check_names( x, type = "named", subset.of = NULL, must.include = NULL, permutation.of = NULL, identical.to = NULL, disjunct.from = NULL, what = "names" ) assertNames( x, type = "named", subset.of = NULL, must.include = NULL, permutation.of = NULL, identical.to = NULL, disjunct.from = NULL, what = "names", .var.name = vname(x), add = NULL ) assert_names( x, type = "named", subset.of = NULL, must.include = NULL, permutation.of = NULL, identical.to = NULL, disjunct.from = NULL, what = "names", .var.name = vname(x), add = NULL ) testNames( x, type = "named", subset.of = NULL, must.include = NULL, permutation.of = NULL, identical.to = NULL, disjunct.from = NULL, what = "names" ) test_names( x, type = "named", subset.of = NULL, must.include = NULL, permutation.of = NULL, identical.to = NULL, disjunct.from = NULL, what = "names" ) expect_names( x, type = "named", subset.of = NULL, must.include = NULL, permutation.of = NULL, identical.to = NULL, disjunct.from = NULL, what = "names", info = NULL, label = vname(x) )
x |
[ |
type |
[character(1)]
Note that for zero-length |
subset.of |
[ |
must.include |
[ |
permutation.of |
[ |
identical.to |
[ |
disjunct.from |
[ |
what |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertNames
/assert_names
return
x
invisibly, whereas
checkNames
/check_names
and
testNames
/test_names
return
TRUE
.
If the check is not successful,
assertNames
/assert_names
throws an error message,
testNames
/test_names
returns FALSE
,
and checkNames
/check_names
return a string with the error message.
The function expect_names
always returns an
expectation
.
Other attributes:
checkClass()
,
checkMultiClass()
,
checkNamed()
x = 1:3 testNames(names(x), "unnamed") names(x) = letters[1:3] testNames(names(x), "unique") cn = c("Species", "Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width") assertNames(names(iris), permutation.of = cn)
x = 1:3 testNames(names(x), "unnamed") names(x) = letters[1:3] testNames(names(x), "unique") cn = c("Species", "Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width") assertNames(names(iris), permutation.of = cn)
Check if an argument is NULL
checkNull(x) check_null(x) assertNull(x, .var.name = vname(x), add = NULL) assert_null(x, .var.name = vname(x), add = NULL) testNull(x) test_null(x)
checkNull(x) check_null(x) assertNull(x, .var.name = vname(x), add = NULL) assert_null(x, .var.name = vname(x), add = NULL) testNull(x) test_null(x)
x |
[any] |
.var.name |
[ |
add |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertNull
/assert_null
return
x
invisibly, whereas
checkNull
/check_null
and
testNull
/test_null
return
TRUE
.
If the check is not successful,
assertNull
/assert_null
throws an error message,
testNull
/test_null
returns FALSE
,
and checkNull
/check_null
return a string with the error message.
The function expect_null
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
testNull(NULL) testNull(1)
testNull(NULL) testNull(1)
Check if an argument is a single numeric value
checkNumber( x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE, null.ok = FALSE ) check_number( x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE, null.ok = FALSE ) assertNumber( x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_number( x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testNumber( x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE, null.ok = FALSE ) test_number( x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE, null.ok = FALSE ) expect_number( x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
checkNumber( x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE, null.ok = FALSE ) check_number( x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE, null.ok = FALSE ) assertNumber( x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_number( x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testNumber( x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE, null.ok = FALSE ) test_number( x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE, null.ok = FALSE ) expect_number( x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
na.ok |
[ |
lower |
[ |
upper |
[ |
finite |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
This function does not distinguish between
NA
, NA_integer_
, NA_real_
, NA_complex_
NA_character_
and NaN
.
Depending on the function prefix:
If the check is successful, the functions
assertNumber
/assert_number
return
x
invisibly, whereas
checkNumber
/check_number
and
testNumber
/test_number
return
TRUE
.
If the check is not successful,
assertNumber
/assert_number
throws an error message,
testNumber
/test_number
returns FALSE
,
and checkNumber
/check_number
return a string with the error message.
The function expect_number
always returns an
expectation
.
Other scalars:
checkCount()
,
checkFlag()
,
checkInt()
,
checkScalar()
,
checkScalarNA()
,
checkString()
testNumber(1) testNumber(1:2)
testNumber(1) testNumber(1:2)
Vectors of storage type “integer” and “double” count as “numeric”, c.f. is.numeric
.
To explicitly check for real integer or double vectors, see checkInteger
, checkIntegerish
or
checkDouble
.
checkNumeric( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) check_numeric( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) assertNumeric( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_numeric( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testNumeric( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) test_numeric( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) expect_numeric( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
checkNumeric( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) check_numeric( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) assertNumeric( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_numeric( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testNumeric( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) test_numeric( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE ) expect_numeric( x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, names = NULL, typed.missing = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
lower |
[ |
upper |
[ |
finite |
[ |
any.missing |
[ |
all.missing |
[ |
len |
[ |
min.len |
[ |
max.len |
[ |
unique |
[ |
sorted |
[ |
names |
[ |
typed.missing |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
This function does not distinguish between
NA
, NA_integer_
, NA_real_
, NA_complex_
NA_character_
and NaN
.
Depending on the function prefix:
If the check is successful, the functions
assertNumeric
/assert_numeric
return
x
invisibly, whereas
checkNumeric
/check_numeric
and
testNumeric
/test_numeric
return
TRUE
.
If the check is not successful,
assertNumeric
/assert_numeric
throws an error message,
testNumeric
/test_numeric
returns FALSE
,
and checkNumeric
/check_numeric
return a string with the error message.
The function expect_numeric
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkPOSIXct()
,
checkRaw()
,
checkVector()
testNumeric(1) testNumeric(1, min.len = 1, lower = 0)
testNumeric(1) testNumeric(1, min.len = 1, lower = 0)
Check the operating system
checkOS(os) check_os(os) assertOS(os, add = NULL, .var.name = NULL) assert_os(os, add = NULL, .var.name = NULL) testOS(os) test_os(os) expect_os(os, info = NULL, label = NULL)
checkOS(os) check_os(os) assertOS(os, add = NULL, .var.name = NULL) assert_os(os, add = NULL, .var.name = NULL) testOS(os) test_os(os) expect_os(os, info = NULL, label = NULL)
os |
[ |
add |
[ |
.var.name |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertOS
/assert_os
return
x
invisibly, whereas
checkOS
/check_os
and
testOS
/test_os
return
TRUE
.
If the check is not successful,
assertOS
/assert_os
throws an error message,
testOS
/test_os
returns FALSE
,
and checkOS
/check_os
return a string with the error message.
The function expect_os
always returns an
expectation
.
testOS("linux")
testOS("linux")
Check if a file path can be used safely to create a file and write to it.
This is checked:
Does dirname(x)
exist?
Does no file under path x
exist?
Is dirname(x)
writable?
Paths are relative to the current working directory.
checkPathForOutput(x, overwrite = FALSE, extension = NULL) check_path_for_output(x, overwrite = FALSE, extension = NULL) assertPathForOutput( x, overwrite = FALSE, extension = NULL, .var.name = vname(x), add = NULL ) assert_path_for_output( x, overwrite = FALSE, extension = NULL, .var.name = vname(x), add = NULL ) testPathForOutput(x, overwrite = FALSE, extension = NULL) test_path_for_output(x, overwrite = FALSE, extension = NULL) expect_path_for_output( x, overwrite = FALSE, extension = NULL, info = NULL, label = vname(x) )
checkPathForOutput(x, overwrite = FALSE, extension = NULL) check_path_for_output(x, overwrite = FALSE, extension = NULL) assertPathForOutput( x, overwrite = FALSE, extension = NULL, .var.name = vname(x), add = NULL ) assert_path_for_output( x, overwrite = FALSE, extension = NULL, .var.name = vname(x), add = NULL ) testPathForOutput(x, overwrite = FALSE, extension = NULL) test_path_for_output(x, overwrite = FALSE, extension = NULL) expect_path_for_output( x, overwrite = FALSE, extension = NULL, info = NULL, label = vname(x) )
x |
[any] |
overwrite |
[ |
extension |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertPathForOutput
/assert_path_for_output
return
x
invisibly, whereas
checkPathForOutput
/check_path_for_output
and
testPathForOutput
/test_path_for_output
return
TRUE
.
If the check is not successful,
assertPathForOutput
/assert_path_for_output
throws an error message,
testPathForOutput
/test_path_for_output
returns FALSE
,
and checkPathForOutput
/check_path_for_output
return a string with the error message.
The function expect_path_for_output
always returns an
expectation
.
Other filesystem:
checkAccess()
,
checkDirectoryExists()
,
checkFileExists()
# Can we create a file in the tempdir? testPathForOutput(file.path(tempdir(), "process.log"))
# Can we create a file in the tempdir? testPathForOutput(file.path(tempdir(), "process.log"))
In contrast to checkSetEqual
, the function tests for a true
permutation of the two vectors and also considers duplicated values.
Missing values are being treated as actual values by default.
Does not work on raw values.
checkPermutation(x, y, na.ok = TRUE) check_permutation(x, y, na.ok = TRUE) assertPermutation(x, y, na.ok = TRUE, .var.name = vname(x), add = NULL) assert_permutation(x, y, na.ok = TRUE, .var.name = vname(x), add = NULL) testPermutation(x, y, na.ok = TRUE) test_permutation(x, y, na.ok = TRUE) expect_permutation(x, y, na.ok = TRUE, info = NULL, label = vname(x))
checkPermutation(x, y, na.ok = TRUE) check_permutation(x, y, na.ok = TRUE) assertPermutation(x, y, na.ok = TRUE, .var.name = vname(x), add = NULL) assert_permutation(x, y, na.ok = TRUE, .var.name = vname(x), add = NULL) testPermutation(x, y, na.ok = TRUE) test_permutation(x, y, na.ok = TRUE) expect_permutation(x, y, na.ok = TRUE, info = NULL, label = vname(x))
x |
[any] |
y |
[ |
na.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertPermutation
/assert_permutation
return
x
invisibly, whereas
checkPermutation
/check_permutation
and
testPermutation
/test_permutation
return
TRUE
.
If the check is not successful,
assertPermutation
/assert_permutation
throws an error message,
testPermutation
/test_permutation
returns FALSE
,
and checkPermutation
/check_permutation
return a string with the error message.
The function expect_permutation
always returns an
expectation
.
The object x
must be of the same type as the set w.r.t. typeof
.
Integers and doubles are both treated as numeric.
Other set:
checkChoice()
,
checkDisjunct()
,
checkSetEqual()
,
checkSubset()
testPermutation(letters[1:2], letters[2:1]) testPermutation(letters[c(1, 1, 2)], letters[1:2]) testPermutation(c(NA, 1, 2), c(1, 2, NA)) testPermutation(c(NA, 1, 2), c(1, 2, NA), na.ok = FALSE)
testPermutation(letters[1:2], letters[2:1]) testPermutation(letters[c(1, 1, 2)], letters[1:2]) testPermutation(c(NA, 1, 2), c(1, 2, NA)) testPermutation(c(NA, 1, 2), c(1, 2, NA), na.ok = FALSE)
Checks that an object is of class POSIXct
.
checkPOSIXct( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, null.ok = FALSE ) check_posixct( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, null.ok = FALSE ) assertPOSIXct( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_posixct( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testPOSIXct( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, null.ok = FALSE ) test_posixct( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, null.ok = FALSE ) expect_posixct( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
checkPOSIXct( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, null.ok = FALSE ) check_posixct( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, null.ok = FALSE ) assertPOSIXct( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_posixct( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testPOSIXct( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, null.ok = FALSE ) test_posixct( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, null.ok = FALSE ) expect_posixct( x, lower = NULL, upper = NULL, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, sorted = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
lower |
[ |
upper |
[ |
any.missing |
[ |
all.missing |
[ |
len |
[ |
min.len |
[ |
max.len |
[ |
unique |
[ |
sorted |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertAtomic
/assert_atomic
return
x
invisibly, whereas
checkAtomic
/check_atomic
and
testAtomic
/test_atomic
return
TRUE
.
If the check is not successful,
assertAtomic
/assert_atomic
throws an error message,
testAtomic
/test_atomic
returns FALSE
,
and checkAtomic
/check_atomic
return a string with the error message.
The function expect_atomic
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkRaw()
,
checkVector()
Check if an argument is an R6 class
checkR6( x, classes = NULL, ordered = FALSE, cloneable = NULL, public = NULL, private = NULL, null.ok = FALSE ) check_r6( x, classes = NULL, ordered = FALSE, cloneable = NULL, public = NULL, private = NULL, null.ok = FALSE ) assertR6( x, classes = NULL, ordered = FALSE, cloneable = NULL, public = NULL, private = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_r6( x, classes = NULL, ordered = FALSE, cloneable = NULL, public = NULL, private = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testR6( x, classes = NULL, ordered = FALSE, cloneable = NULL, public = NULL, private = NULL, null.ok = FALSE ) test_r6( x, classes = NULL, ordered = FALSE, cloneable = NULL, public = NULL, private = NULL, null.ok = FALSE ) expect_r6( x, classes = NULL, ordered = FALSE, cloneable = NULL, public = NULL, private = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
checkR6( x, classes = NULL, ordered = FALSE, cloneable = NULL, public = NULL, private = NULL, null.ok = FALSE ) check_r6( x, classes = NULL, ordered = FALSE, cloneable = NULL, public = NULL, private = NULL, null.ok = FALSE ) assertR6( x, classes = NULL, ordered = FALSE, cloneable = NULL, public = NULL, private = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_r6( x, classes = NULL, ordered = FALSE, cloneable = NULL, public = NULL, private = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testR6( x, classes = NULL, ordered = FALSE, cloneable = NULL, public = NULL, private = NULL, null.ok = FALSE ) test_r6( x, classes = NULL, ordered = FALSE, cloneable = NULL, public = NULL, private = NULL, null.ok = FALSE ) expect_r6( x, classes = NULL, ordered = FALSE, cloneable = NULL, public = NULL, private = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
classes |
[ |
ordered |
[ |
cloneable |
[ |
public |
[ |
private |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertClass
/assert_class
return
x
invisibly, whereas
checkClass
/check_class
and
testClass
/test_class
return
TRUE
.
If the check is not successful,
assertClass
/assert_class
throws an error message,
testClass
/test_class
returns FALSE
,
and checkClass
/check_class
return a string with the error message.
The function expect_class
always returns an
expectation
.
Other classes:
checkClass()
,
checkMultiClass()
library(R6) generator = R6Class("Bar", public = list(a = 5), private = list(b = 42), active = list(c = function() 99) ) x = generator$new() checkR6(x, "Bar", cloneable = TRUE, public = "a")
library(R6) generator = R6Class("Bar", public = list(a = 5), private = list(b = 42), active = list(c = function() 99) ) x = generator$new() checkR6(x, "Bar", cloneable = TRUE, public = "a")
Check if an argument is a raw vector
checkRaw( x, len = NULL, min.len = NULL, max.len = NULL, names = NULL, null.ok = FALSE ) check_raw( x, len = NULL, min.len = NULL, max.len = NULL, names = NULL, null.ok = FALSE ) assertRaw( x, len = NULL, min.len = NULL, max.len = NULL, names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_raw( x, len = NULL, min.len = NULL, max.len = NULL, names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testRaw( x, len = NULL, min.len = NULL, max.len = NULL, names = NULL, null.ok = FALSE ) test_raw( x, len = NULL, min.len = NULL, max.len = NULL, names = NULL, null.ok = FALSE ) expect_raw( x, len = NULL, min.len = NULL, max.len = NULL, names = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
checkRaw( x, len = NULL, min.len = NULL, max.len = NULL, names = NULL, null.ok = FALSE ) check_raw( x, len = NULL, min.len = NULL, max.len = NULL, names = NULL, null.ok = FALSE ) assertRaw( x, len = NULL, min.len = NULL, max.len = NULL, names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_raw( x, len = NULL, min.len = NULL, max.len = NULL, names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testRaw( x, len = NULL, min.len = NULL, max.len = NULL, names = NULL, null.ok = FALSE ) test_raw( x, len = NULL, min.len = NULL, max.len = NULL, names = NULL, null.ok = FALSE ) expect_raw( x, len = NULL, min.len = NULL, max.len = NULL, names = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
len |
[ |
min.len |
[ |
max.len |
[ |
names |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertRaw
/assert_raw
return
x
invisibly, whereas
checkRaw
/check_raw
and
testRaw
/test_raw
return
TRUE
.
If the check is not successful,
assertRaw
/assert_raw
throws an error message,
testRaw
/test_raw
returns FALSE
,
and checkRaw
/check_raw
return a string with the error message.
The function expect_raw
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkVector()
testRaw(as.raw(2), min.len = 1L)
testRaw(as.raw(2), min.len = 1L)
Check if an argument is a single atomic value
checkScalar(x, na.ok = FALSE, null.ok = FALSE) check_scalar(x, na.ok = FALSE, null.ok = FALSE) assertScalar( x, na.ok = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_scalar( x, na.ok = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testScalar(x, na.ok = FALSE, null.ok = FALSE) test_scalar(x, na.ok = FALSE, null.ok = FALSE) expect_scalar(x, na.ok = FALSE, null.ok = FALSE, info = NULL, label = vname(x))
checkScalar(x, na.ok = FALSE, null.ok = FALSE) check_scalar(x, na.ok = FALSE, null.ok = FALSE) assertScalar( x, na.ok = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_scalar( x, na.ok = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testScalar(x, na.ok = FALSE, null.ok = FALSE) test_scalar(x, na.ok = FALSE, null.ok = FALSE) expect_scalar(x, na.ok = FALSE, null.ok = FALSE, info = NULL, label = vname(x))
x |
[any] |
na.ok |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
This function does not distinguish between
NA
, NA_integer_
, NA_real_
, NA_complex_
NA_character_
and NaN
.
Depending on the function prefix:
If the check is successful, the functions
assertScalar
/assert_scalar
return
x
invisibly, whereas
checkScalar
/check_scalar
and
testScalar
/test_scalar
return
TRUE
.
If the check is not successful,
assertScalar
/assert_scalar
throws an error message,
testScalar
/test_scalar
returns FALSE
,
and checkScalar
/check_scalar
return a string with the error message.
The function expect_scalar
always returns an
expectation
.
Other scalars:
checkCount()
,
checkFlag()
,
checkInt()
,
checkNumber()
,
checkScalarNA()
,
checkString()
testScalar(1) testScalar(1:10)
testScalar(1) testScalar(1:10)
Check if an argument is a single missing value
checkScalarNA(x, null.ok = FALSE) check_scalar_na(x, null.ok = FALSE) assertScalarNA(x, null.ok = FALSE, .var.name = vname(x), add = NULL) assert_scalar_na(x, null.ok = FALSE, .var.name = vname(x), add = NULL) testScalarNA(x, null.ok = FALSE) test_scalar_na(x, null.ok = FALSE) expect_scalar_na(x, null.ok = FALSE, info = NULL, label = vname(x))
checkScalarNA(x, null.ok = FALSE) check_scalar_na(x, null.ok = FALSE) assertScalarNA(x, null.ok = FALSE, .var.name = vname(x), add = NULL) assert_scalar_na(x, null.ok = FALSE, .var.name = vname(x), add = NULL) testScalarNA(x, null.ok = FALSE) test_scalar_na(x, null.ok = FALSE) expect_scalar_na(x, null.ok = FALSE, info = NULL, label = vname(x))
x |
[any] |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertScalarNA
/assert_scalar_na
return
x
invisibly, whereas
checkScalarNA
/check_scalar_na
and
testScalarNA
/test_scalar_na
return
TRUE
.
If the check is not successful,
assertScalarNA
/assert_scalar_na
throws an error message,
testScalarNA
/test_scalar_na
returns FALSE
,
and checkScalarNA
/check_scalar_na
return a string with the error message.
The function expect_scalar_na
always returns an
expectation
.
Other scalars:
checkCount()
,
checkFlag()
,
checkInt()
,
checkNumber()
,
checkScalar()
,
checkString()
testScalarNA(1) testScalarNA(NA_real_) testScalarNA(rep(NA, 2))
testScalarNA(1) testScalarNA(NA_real_) testScalarNA(rep(NA, 2))
Check if an argument is equal to a given set
checkSetEqual(x, y, ordered = FALSE, fmatch = FALSE) check_set_equal(x, y, ordered = FALSE, fmatch = FALSE) assertSetEqual( x, y, ordered = FALSE, fmatch = FALSE, .var.name = vname(x), add = NULL ) assert_set_equal( x, y, ordered = FALSE, fmatch = FALSE, .var.name = vname(x), add = NULL ) testSetEqual(x, y, ordered = FALSE, fmatch = FALSE) test_set_equal(x, y, ordered = FALSE, fmatch = FALSE) expect_set_equal( x, y, ordered = FALSE, fmatch = FALSE, info = NULL, label = vname(x) )
checkSetEqual(x, y, ordered = FALSE, fmatch = FALSE) check_set_equal(x, y, ordered = FALSE, fmatch = FALSE) assertSetEqual( x, y, ordered = FALSE, fmatch = FALSE, .var.name = vname(x), add = NULL ) assert_set_equal( x, y, ordered = FALSE, fmatch = FALSE, .var.name = vname(x), add = NULL ) testSetEqual(x, y, ordered = FALSE, fmatch = FALSE) test_set_equal(x, y, ordered = FALSE, fmatch = FALSE) expect_set_equal( x, y, ordered = FALSE, fmatch = FALSE, info = NULL, label = vname(x) )
x |
[any] |
y |
[ |
ordered |
[ |
fmatch |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertSubset
/assert_subset
return
x
invisibly, whereas
checkSubset
/check_subset
and
testSubset
/test_subset
return
TRUE
.
If the check is not successful,
assertSubset
/assert_subset
throws an error message,
testSubset
/test_subset
returns FALSE
,
and checkSubset
/check_subset
return a string with the error message.
The function expect_subset
always returns an
expectation
.
The object x
must be of the same type as the set w.r.t. typeof
.
Integers and doubles are both treated as numeric.
Other set:
checkChoice()
,
checkDisjunct()
,
checkPermutation()
,
checkSubset()
testSetEqual(c("a", "b"), c("a", "b")) testSetEqual(1:3, 1:4) # x is not converted before the comparison (except for numerics) testSetEqual(factor("a"), "a") testSetEqual(1, "1") testSetEqual(1, as.integer(1))
testSetEqual(c("a", "b"), c("a", "b")) testSetEqual(1:3, 1:4) # x is not converted before the comparison (except for numerics) testSetEqual(factor("a"), "a") testSetEqual(1, "1") testSetEqual(1, as.integer(1))
A string is defined as a scalar character vector.
To check for vectors of arbitrary length, see checkCharacter
.
checkString( x, na.ok = FALSE, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, null.ok = FALSE ) check_string( x, na.ok = FALSE, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, null.ok = FALSE ) assertString( x, na.ok = FALSE, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_string( x, na.ok = FALSE, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testString( x, na.ok = FALSE, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, null.ok = FALSE ) test_string( x, na.ok = FALSE, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, null.ok = FALSE ) expect_string( x, na.ok = FALSE, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
checkString( x, na.ok = FALSE, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, null.ok = FALSE ) check_string( x, na.ok = FALSE, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, null.ok = FALSE ) assertString( x, na.ok = FALSE, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_string( x, na.ok = FALSE, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, null.ok = FALSE, .var.name = vname(x), add = NULL ) testString( x, na.ok = FALSE, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, null.ok = FALSE ) test_string( x, na.ok = FALSE, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, null.ok = FALSE ) expect_string( x, na.ok = FALSE, n.chars = NULL, min.chars = NULL, max.chars = NULL, pattern = NULL, fixed = NULL, ignore.case = FALSE, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
na.ok |
[ |
n.chars |
[ |
min.chars |
[ |
max.chars |
[ |
pattern |
[ |
fixed |
[ |
ignore.case |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
This function does not distinguish between
NA
, NA_integer_
, NA_real_
, NA_complex_
NA_character_
and NaN
.
Depending on the function prefix:
If the check is successful, the functions
assertString
/assert_string
return
x
invisibly, whereas
checkString
/check_string
and
testString
/test_string
return
TRUE
.
If the check is not successful,
assertString
/assert_string
throws an error message,
testString
/test_string
returns FALSE
,
and checkString
/check_string
return a string with the error message.
The function expect_string
always returns an
expectation
.
Other scalars:
checkCount()
,
checkFlag()
,
checkInt()
,
checkNumber()
,
checkScalar()
,
checkScalarNA()
testString("a") testString(letters)
testString("a") testString(letters)
Check if an argument is a subset of a given set
checkSubset(x, choices, empty.ok = TRUE, fmatch = FALSE) check_subset(x, choices, empty.ok = TRUE, fmatch = FALSE) assertSubset( x, choices, empty.ok = TRUE, fmatch = FALSE, .var.name = vname(x), add = NULL ) assert_subset( x, choices, empty.ok = TRUE, fmatch = FALSE, .var.name = vname(x), add = NULL ) testSubset(x, choices, empty.ok = TRUE, fmatch = FALSE) test_subset(x, choices, empty.ok = TRUE, fmatch = FALSE) expect_subset( x, choices, empty.ok = TRUE, fmatch = FALSE, info = NULL, label = vname(x) )
checkSubset(x, choices, empty.ok = TRUE, fmatch = FALSE) check_subset(x, choices, empty.ok = TRUE, fmatch = FALSE) assertSubset( x, choices, empty.ok = TRUE, fmatch = FALSE, .var.name = vname(x), add = NULL ) assert_subset( x, choices, empty.ok = TRUE, fmatch = FALSE, .var.name = vname(x), add = NULL ) testSubset(x, choices, empty.ok = TRUE, fmatch = FALSE) test_subset(x, choices, empty.ok = TRUE, fmatch = FALSE) expect_subset( x, choices, empty.ok = TRUE, fmatch = FALSE, info = NULL, label = vname(x) )
x |
[any] |
choices |
[ |
empty.ok |
[ |
fmatch |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertSubset
/assert_subset
return
x
invisibly, whereas
checkSubset
/check_subset
and
testSubset
/test_subset
return
TRUE
.
If the check is not successful,
assertSubset
/assert_subset
throws an error message,
testSubset
/test_subset
returns FALSE
,
and checkSubset
/check_subset
return a string with the error message.
The function expect_subset
always returns an
expectation
.
The object x
must be of the same type as the set w.r.t. typeof
.
Integers and doubles are both treated as numeric.
Other set:
checkChoice()
,
checkDisjunct()
,
checkPermutation()
,
checkSetEqual()
testSubset(c("a", "z"), letters) testSubset("ab", letters) testSubset("Species", names(iris)) # x is not converted before the comparison (except for numerics) testSubset(factor("a"), "a") testSubset(1, "1") testSubset(1, as.integer(1))
testSubset(c("a", "z"), letters) testSubset("ab", letters) testSubset("Species", names(iris)) # x is not converted before the comparison (except for numerics) testSubset(factor("a"), "a") testSubset(1, "1") testSubset(1, as.integer(1))
Check if an argument is a tibble
checkTibble( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) check_tibble( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) assertTibble( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_tibble( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testTibble( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) test_tibble( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) expect_tibble( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
checkTibble( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) check_tibble( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) assertTibble( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_tibble( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testTibble( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) test_tibble( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE ) expect_tibble( x, types = character(0L), any.missing = TRUE, all.missing = TRUE, min.rows = NULL, max.rows = NULL, min.cols = NULL, max.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, null.ok = FALSE, info = NULL, label = vname(x) )
x |
[any] |
types |
[ |
any.missing |
[ |
all.missing |
[ |
min.rows |
[ |
max.rows |
[ |
min.cols |
[ |
max.cols |
[ |
nrows |
[ |
ncols |
[ |
row.names |
[ |
col.names |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertTibble
/assert_tibble
return
x
invisibly, whereas
checkTibble
/check_tibble
and
testTibble
/test_tibble
return
TRUE
.
If the check is not successful,
assertTibble
/assert_tibble
throws an error message,
testTibble
/test_tibble
returns FALSE
,
and checkTibble
/check_tibble
return a string with the error message.
The function expect_tibble
always returns an
expectation
.
Other compound:
checkArray()
,
checkDataFrame()
,
checkDataTable()
,
checkMatrix()
library(tibble) x = as_tibble(iris) testTibble(x) testTibble(x, nrow = 150, any.missing = FALSE)
library(tibble) x = as_tibble(iris) testTibble(x) testTibble(x, nrow = 150, any.missing = FALSE)
Simply checks if an argument is TRUE
.
checkTRUE(x, na.ok = FALSE) check_true(x, na.ok = FALSE) assertTRUE(x, na.ok = FALSE, .var.name = vname(x), add = NULL) assert_true(x, na.ok = FALSE, .var.name = vname(x), add = NULL) testTRUE(x, na.ok = FALSE) test_true(x, na.ok = FALSE)
checkTRUE(x, na.ok = FALSE) check_true(x, na.ok = FALSE) assertTRUE(x, na.ok = FALSE, .var.name = vname(x), add = NULL) assert_true(x, na.ok = FALSE, .var.name = vname(x), add = NULL) testTRUE(x, na.ok = FALSE) test_true(x, na.ok = FALSE)
x |
[any] |
na.ok |
[ |
.var.name |
[ |
add |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertTRUE.
/assert_true.
return
x
invisibly, whereas
checkTRUE.
/check_true.
and
testTRUE.
/test_true.
return
TRUE
.
If the check is not successful,
assertTRUE.
/assert_true.
throws an error message,
testTRUE.
/test_true.
returns FALSE
,
and checkTRUE.
/check_true.
return a string with the error message.
The function expect_true.
always returns an
expectation
.
testTRUE(TRUE) testTRUE(FALSE)
testTRUE(TRUE) testTRUE(FALSE)
Check if an argument is a vector
checkVector( x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) check_vector( x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) assertVector( x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_vector( x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testVector( x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) test_vector( x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE )
checkVector( x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) check_vector( x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) assertVector( x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) assert_vector( x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE, .var.name = vname(x), add = NULL ) testVector( x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE ) test_vector( x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, null.ok = FALSE )
x |
[any] |
strict |
[ |
any.missing |
[ |
all.missing |
[ |
len |
[ |
min.len |
[ |
max.len |
[ |
unique |
[ |
names |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
Depending on the function prefix:
If the check is successful, the functions
assertVector
/assert_vector
return
x
invisibly, whereas
checkVector
/check_vector
and
testVector
/test_vector
return
TRUE
.
If the check is not successful,
assertVector
/assert_vector
throws an error message,
testVector
/test_vector
returns FALSE
,
and checkVector
/check_vector
return a string with the error message.
The function expect_vector
always returns an
expectation
.
Other basetypes:
checkArray()
,
checkAtomic()
,
checkAtomicVector()
,
checkCharacter()
,
checkComplex()
,
checkDataFrame()
,
checkDate()
,
checkDouble()
,
checkEnvironment()
,
checkFactor()
,
checkFormula()
,
checkFunction()
,
checkInteger()
,
checkIntegerish()
,
checkList()
,
checkLogical()
,
checkMatrix()
,
checkNull()
,
checkNumeric()
,
checkPOSIXct()
,
checkRaw()
Other atomicvector:
checkAtomic()
,
checkAtomicVector()
testVector(letters, min.len = 1L, any.missing = FALSE)
testVector(letters, min.len = 1L, any.missing = FALSE)
makeAssertion
is the internal function used to evaluate the result of a
check and throw an exception if necessary.
makeAssertionFunction
can be used to automatically create an assertion
function based on a check function (see example).
makeAssertion(x, res, var.name, collection) makeAssertionFunction( check.fun, c.fun = NULL, use.namespace = TRUE, coerce = FALSE, env = parent.frame() )
makeAssertion(x, res, var.name, collection) makeAssertionFunction( check.fun, c.fun = NULL, use.namespace = TRUE, coerce = FALSE, env = parent.frame() )
x |
[any] |
res |
[ |
var.name |
[ |
collection |
[ |
check.fun |
[ |
c.fun |
[ |
use.namespace |
[ |
coerce |
[ |
env |
[ |
makeAssertion
invisibly returns the checked object if the check was successful,
and an exception is raised (or its message stored in the collection) otherwise.
makeAssertionFunction
returns a function
.
Other CustomConstructors:
makeExpectation()
,
makeTest()
# Simple custom check function checkFalse = function(x) if (!identical(x, FALSE)) "Must be FALSE" else TRUE # Create the respective assert function assertFalse = function(x, .var.name = vname(x), add = NULL) { res = checkFalse(x) makeAssertion(x, res, .var.name, add) } # Alternative: Automatically create such a function assertFalse = makeAssertionFunction(checkFalse) print(assertFalse)
# Simple custom check function checkFalse = function(x) if (!identical(x, FALSE)) "Must be FALSE" else TRUE # Create the respective assert function assertFalse = function(x, .var.name = vname(x), add = NULL) { res = checkFalse(x) makeAssertion(x, res, .var.name, add) } # Alternative: Automatically create such a function assertFalse = makeAssertionFunction(checkFalse) print(assertFalse)
makeExpectation
is the internal function used to evaluate the result of a
check and turn it into an expectation
.
makeExceptionFunction
can be used to automatically create an expectation
function based on a check function (see example).
makeExpectation(x, res, info, label) makeExpectationFunction( check.fun, c.fun = NULL, use.namespace = FALSE, env = parent.frame() )
makeExpectation(x, res, info, label) makeExpectationFunction( check.fun, c.fun = NULL, use.namespace = FALSE, env = parent.frame() )
x |
[any] |
res |
[ |
info |
[ |
label |
[ |
check.fun |
[ |
c.fun |
[ |
use.namespace |
[ |
env |
[ |
makeExpectation
invisibly returns the checked object.
makeExpectationFunction
returns a function
.
Other CustomConstructors:
makeAssertion()
,
makeTest()
# Simple custom check function checkFalse = function(x) if (!identical(x, FALSE)) "Must be FALSE" else TRUE # Create the respective expect function expect_false = function(x, info = NULL, label = vname(x)) { res = checkFalse(x) makeExpectation(x, res, info = info, label = label) } # Alternative: Automatically create such a function expect_false = makeExpectationFunction(checkFalse) print(expect_false)
# Simple custom check function checkFalse = function(x) if (!identical(x, FALSE)) "Must be FALSE" else TRUE # Create the respective expect function expect_false = function(x, info = NULL, label = vname(x)) { res = checkFalse(x) makeExpectation(x, res, info = info, label = label) } # Alternative: Automatically create such a function expect_false = makeExpectationFunction(checkFalse) print(expect_false)
makeTest
is the internal function used to evaluate the result of a
check and throw an exception if necessary.
This function is currently only a stub and just calls isTRUE
.
makeTestFunction
can be used to automatically create an assertion
function based on a check function (see example).
makeTest(res) makeTestFunction(check.fun, c.fun = NULL, env = parent.frame())
makeTest(res) makeTestFunction(check.fun, c.fun = NULL, env = parent.frame())
res |
[ |
check.fun |
[ |
c.fun |
[ |
env |
[ |
makeTest
returns TRUE
if the check is successful and FALSE
otherwise.
makeTestFunction
returns a function
.
Other CustomConstructors:
makeAssertion()
,
makeExpectation()
# Simple custom check function checkFalse = function(x) if (!identical(x, FALSE)) "Must be FALSE" else TRUE # Create the respective test function testFalse = function(x) { res = checkFalse(x) makeTest(res) } # Alternative: Automatically create such a function testFalse = makeTestFunction(checkFalse) print(testFalse)
# Simple custom check function checkFalse = function(x) if (!identical(x, FALSE)) "Must be FALSE" else TRUE # Create the respective test function testFalse = function(x) { res = checkFalse(x) makeTest(res) } # Alternative: Automatically create such a function testFalse = makeTestFunction(checkFalse) print(testFalse)
This is an extensions to match.arg
with support for AssertCollection
.
The behavior is very similar to match.arg
, except that NULL
is not
a valid value for x
.
matchArg(x, choices, several.ok = FALSE, .var.name = vname(x), add = NULL)
matchArg(x, choices, several.ok = FALSE, .var.name = vname(x), add = NULL)
x |
[character] |
choices |
[character()] |
several.ok |
[logical(1)] |
.var.name |
[ |
add |
[ |
Subset of choices
.
matchArg("k", choices = c("kendall", "pearson"))
matchArg("k", choices = c("kendall", "pearson"))
The provided functions parse rules which allow to express some of the most frequent argument checks by typing just a few letters.
qassert(x, rules, .var.name = vname(x)) qtest(x, rules) qexpect(x, rules, info = NULL, label = vname(x))
qassert(x, rules, .var.name = vname(x)) qtest(x, rules) qexpect(x, rules, info = NULL, label = vname(x))
x |
[any] |
rules |
[ |
.var.name |
[ |
info |
[ |
label |
[ |
The rule is specified in up to three parts.
Class and missingness check. The first letter is an abbreviation for the class. If it is provided uppercase, missing values are prohibited. Supported abbreviations:
[bB] |
Bool / logical. |
[iI] |
Integer. |
[xX] |
Integerish (numeric convertible to integer, see checkIntegerish ). |
[rR] |
Real / double. |
[cC] |
Complex. |
[nN] |
Numeric (integer or double). |
[sS] |
String / character. |
[fF] |
Factor |
[aA] |
Atomic. |
[vV] |
Atomic vector (see checkAtomicVector ). |
[lL] |
List. Missingness is defined as NULL element. |
[mM] |
Matrix. |
[dD] |
Data.frame. Missingness is checked recursively on columns. |
[pP] |
POSIXct date. |
[e] |
Environment. |
[0] |
NULL . |
[*] |
placeholder to allow any type. |
Note that the check for missingness does not distinguish between
NaN
and NA
. Infinite values are not treated as missing, but
can be caught using boundary checks (part 3).
Length definition. This can be one of
[*] |
any length, |
[?] |
length of zero or one, |
[+] |
length of at least one, or |
[0-9]+ |
exact length specified as integer. |
Preceding the exact length with one of the comparison operators =
/==
,
<
, <=
, >=
or >
is also supported.
Range check as two numbers separated by a comma, enclosed by square brackets
(endpoint included) or parentheses (endpoint excluded).
For example, “[0, 3)” results in all(x >= 0 & x < 3)
.
The lower and upper bound may be omitted which is the equivalent of a negative or
positive infinite bound, respectively.
By definition [0,]
contains Inf
, while [0,)
does not.
The same holds for the left (lower) boundary and -Inf
.
E.g., the rule “N1()” checks for a single finite numeric which is not NA,
while “N1[)” allows -Inf
.
qassert
throws an R
exception if object x
does
not comply to at least one of the rules
and returns the tested object invisibly
otherwise.
qtest
behaves the same way but returns FALSE
if none of the
rules
comply.
qexpect
is intended to be inside the unit test framework testthat
and
returns an expectation
.
The functions are inspired by the blog post of Bogumił Kamiński: http://rsnippets.blogspot.de/2013/06/testing-function-agruments-in-gnu-r.html. The implementation is mostly written in C to minimize the overhead.
qtestr
and qassertr
for efficient checks
of list elements and data frame columns.
# logical of length 1 qtest(NA, "b1") # logical of length 1, NA not allowed qtest(NA, "B1") # logical of length 0 or 1, NA not allowed qtest(TRUE, "B?") # numeric with length > 0 qtest(runif(10), "n+") # integer with length > 0, NAs not allowed, all integers >= 0 and < Inf qtest(1:3, "I+[0,)") # either an emtpy list or a character vector with <=5 elements qtest(1, c("l0", "s<=5")) # data frame with at least one column and no missing value in any column qtest(iris, "D+")
# logical of length 1 qtest(NA, "b1") # logical of length 1, NA not allowed qtest(NA, "B1") # logical of length 0 or 1, NA not allowed qtest(TRUE, "B?") # numeric with length > 0 qtest(runif(10), "n+") # integer with length > 0, NAs not allowed, all integers >= 0 and < Inf qtest(1:3, "I+[0,)") # either an emtpy list or a character vector with <=5 elements qtest(1, c("l0", "s<=5")) # data frame with at least one column and no missing value in any column qtest(iris, "D+")
These functions are the tuned counterparts of qtest
,
qassert
and qexpect
tailored for recursive
checks of list elements or data frame columns.
qassertr(x, rules, .var.name = vname(x)) qtestr(x, rules, depth = 1L) qexpectr(x, rules, info = NULL, label = vname(x))
qassertr(x, rules, .var.name = vname(x)) qtestr(x, rules, depth = 1L) qexpectr(x, rules, info = NULL, label = vname(x))
x |
[ |
rules |
[ |
.var.name |
[ |
depth |
[ |
info |
[ |
label |
[ |
See qassert
.
# All list elements are integers with length >= 1? qtestr(as.list(1:10), "i+") # All list elements (i.e. data frame columns) are numeric? qtestr(iris, "n") # All list elements are numeric, w/o NAs? qtestr(list(a = 1:3, b = rnorm(1), c = letters), "N+") # All list elements are numeric OR character qtestr(list(a = 1:3, b = rnorm(1), c = letters), c("N+", "S+"))
# All list elements are integers with length >= 1? qtestr(as.list(1:10), "i+") # All list elements (i.e. data frame columns) are numeric? qtestr(iris, "n") # All list elements are numeric, w/o NAs? qtestr(list(a = 1:3, b = rnorm(1), c = letters), "N+") # All list elements are numeric OR character qtestr(list(a = 1:3, b = rnorm(1), c = letters), c("N+", "S+"))
Allows to explicitly select a backend for the unit tests.
Currently supported are "testthat"
and "tinytest"
.
The respective package must be installed and are loaded (but not attached).
If this function is not explicitly called, defaults to "testthat"
unless
the "tinytest"
's namespace is loaded.
register_test_backend(name)
register_test_backend(name)
name |
[ |
NULL
(invisibly).
Tries to heuristically determine the variable name of x
in the parent frame
with a combination of deparse
and substitute
.
Used for checkmate's error messages.
vname(x)
vname(x)
x |
[ANY] |
[character(1)
] Variable name.
A quick C implementation for “which.first” (head(which(x), 1)
) and
“which.last” (tail(which(x), 1)
).
wf(x, use.names = TRUE) wl(x, use.names = TRUE)
wf(x, use.names = TRUE) wl(x, use.names = TRUE)
x |
[ |
use.names |
[ |
[integer(1)
| integer(0)
].
Returns the index of the first/last TRUE
value in x
or
an empty integer vector if none is found. NAs are ignored.
wf(c(FALSE, TRUE)) wl(c(FALSE, FALSE)) wf(NA)
wf(c(FALSE, TRUE)) wl(c(FALSE, FALSE)) wf(NA)