| Type: | Package |
| 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. |
| Version: | 2.3.4 |
| URL: | https://mllg.github.io/checkmate/,https://github.com/mllg/checkmate |
| URLNote: | https://github.com/mllg/checkmate |
| BugReports: | https://github.com/mllg/checkmate/issues |
| NeedsCompilation: | yes |
| ByteCompile: | yes |
| Encoding: | UTF-8 |
| Depends: | R (≥ 3.0.0) |
| Imports: | backports (≥ 1.1.0), utils |
| Suggests: | R6, fastmatch, data.table (≥ 1.9.8), devtools, ggplot2,knitr, magrittr, microbenchmark, rmarkdown, testthat (≥3.0.4), tinytest (≥ 1.1.0), tibble |
| License: | BSD_3_clause + file LICENSE |
| VignetteBuilder: | knitr |
| RoxygenNote: | 7.3.3 |
| Collate: | 'AssertCollection.R' 'allMissing.R' 'anyInfinite.R''anyMissing.R' 'anyNaN.R' 'asInteger.R' 'assert.R' 'helper.R''makeExpectation.R' 'makeTest.R' 'makeAssertion.R''checkAccess.R' 'checkArray.R' 'checkAtomic.R''checkAtomicVector.R' 'checkCharacter.R' 'checkChoice.R''checkClass.R' 'checkComplex.R' 'checkCount.R''checkDataFrame.R' 'checkDataTable.R' 'checkDate.R''checkDirectoryExists.R' 'checkDisjunct.R' 'checkDouble.R''checkEnvironment.R' 'checkFALSE.R' 'checkFactor.R''checkFileExists.R' 'checkFlag.R' 'checkFormula.R''checkFunction.R' 'checkInt.R' 'checkInteger.R''checkIntegerish.R' 'checkList.R' 'checkLogical.R''checkMatrix.R' 'checkMultiClass.R' 'checkNamed.R''checkNames.R' 'checkNull.R' 'checkNumber.R' 'checkNumeric.R''checkOS.R' 'checkPOSIXct.R' 'checkPathForOutput.R''checkPermutation.R' 'checkR6.R' 'checkRaw.R' 'checkScalar.R''checkScalarNA.R' 'checkSetEqual.R' 'checkString.R''checkSubset.R' 'checkTRUE.R' 'checkTibble.R' 'checkVector.R''coalesce.R' 'isIntegerish.R' 'matchArg.R' 'qassert.R''qassertr.R' 'vname.R' 'wfwl.R' 'zzz.R' |
| Packaged: | 2026-02-02 10:59:55 UTC; michel |
| Author: | Michel Lang |
| Maintainer: | Michel Lang <michellang@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-02-03 08:40:02 UTC |
checkmate: 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.
Check scalars
Check vectors
Check attributes
checkNamed(deprecated)
Check compound types
Check other built-in R types
Check sets
File IO
Popular data types of third party packages
Safe coercion to integer
Quick argument checks using a DSL
Misc
checkOS(check operating system)assert(combine multiple checks into an assertion)wf(which.first and which.last)
Author(s)
Maintainer: Michel Langmichellang@gmail.com (ORCID)
Other contributors:
Bernd Bischlbernd_bischl@gmx.net [contributor]
Dénes Tóthtoth.denes@kogentum.hu (ORCID) [contributor]
See Also
Useful links:
Report bugs athttps://github.com/mllg/checkmate/issues
Coalesce operator
Description
Returns the left hand side if not missing norNULL, andthe right hand side otherwise.
Usage
lhs %??% rhsArguments
lhs | [ |
rhs | [ |
Value
Eitherlhs orrhs.
Examples
print(NULL %??% 1 %??% 2)print(names(iris) %??% letters[seq_len(ncol(iris))])Collect multiple assertions
Description
The functionmakeAssertCollection() returns a simple stack-likeclosure you can pass to all functions of theassert*-family.All messages get collected and can be reported withreportAssertions().Alternatively, you can easily write your own report function or customize the the output ofthe report function to a certain degree.See the example on how to push custom messages or retrieve all stored messages.
Usage
makeAssertCollection()reportAssertions(collection)Arguments
collection | [ |
Value
makeAssertCollection() returns an object of class “AssertCollection” andreportCollection returns invisiblyTRUE if no error is thrown (i.e., no message wascollected).
Examples
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 if an object contains missing values
Description
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 (seeis.atomic), lists and data frames.Missingness is defined asNA orNaN for atomic types and data frame columns,NULL is defined as missing for lists.allMissing applied to adata.frame returnsTRUE if at least one column hasonly non-missing values. If you want to perform the less frequent check that there is at leasta single non-missing observation present in thedata.frame, useall(sapply(df, allMissing)) instead.
Usage
allMissing(x)anyMissing(x)Arguments
x | [ |
Value
[logical(1)] ReturnsTRUE if any (anyMissing) or all (allMissing)elements ofx are missing (see details),FALSE otherwise.
Examples
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 = irisx[, "Species"] = NAanyMissing(x)allMissing(x)Check if an object contains infinite values
Description
Supported are atomic types (seeis.atomic), lists and data frames.
Usage
anyInfinite(x)Arguments
x | [ |
Value
[logical(1)] ReturnsTRUE if any element is-Inf orInf.
Examples
anyInfinite(1:10)anyInfinite(c(1:10, Inf))iris[3, 3] = InfanyInfinite(iris)Check if an object contains NaN values
Description
Supported are atomic types (seeis.atomic), lists and data frames.
Usage
anyNaN(x)Arguments
x | [ |
Value
[logical(1)] ReturnsTRUE if any element isNaN.
Examples
anyNaN(1:10)anyNaN(c(1:10, NaN))iris[3, 3] = NaNanyNaN(iris)Convert an argument to an integer
Description
asInteger is intended to be used for vectors whileasInt isa specialization for scalar integers andasCount for scalarnon-negative integers.Convertible are (a) atomic vectors with all elementsNAand (b) double vectors with all elements being withintolrange of an integer.
Note that these functions may be deprecated in the future.Instead, it is advised to useassertCount,assertInt orassertIntegerish withargumentcoerce set toTRUE instead.
Usage
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))Arguments
x | [ |
tol | [ |
lower | [ |
upper | [ |
any.missing | [ |
all.missing | [ |
len | [ |
min.len | [ |
max.len | [ |
unique | [ |
sorted | [ |
names | [ |
.var.name | [ |
na.ok | [ |
positive | [ |
Details
This function does not distinguish betweenNA,NA_integer_,NA_real_,NA_complex_NA_character_ andNaN.
Value
Convertedx.
Examples
asInteger(c(1, 2, 3))asCount(1)asInt(1)Combine multiple checks into one assertion
Description
You can call this function with an arbitrary number of ofcheck*functions, i.e. functions provided by this package or your own functions whichreturnTRUE on success and the error message ascharacter(1) otherwise.The resulting assertion is successful, ifcombine is“or” (default) and at least one check evaluates toTRUE orcombine is “and” and all checks evaluate toTRUE.Otherwise,assert throws an informative error message.
Usage
assert(..., combine = "or", .var.name = NULL, add = NULL)Arguments
... | [ |
combine | [ |
.var.name | [ |
add | [ |
Value
Throws an error (or pushes the error message to anAssertCollection ifadd is notNULL)if the checks fail and invisibly returnsTRUE otherwise.
Examples
x = 1:10assert(checkNull(x), checkInteger(x, any.missing = FALSE))collection <- makeAssertCollection()assert(checkChoice(x, c("a", "b")), checkDataFrame(x), add = collection)collection$getMessages()Check file system access rights
Description
Check file system access rights
Usage
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))Arguments
x | [ |
access | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertAccess/assert_access returnx invisibly, whereascheckAccess/check_access andtestAccess/test_access returnTRUE.If the check is not successful,assertAccess/assert_accessthrows an error message,testAccess/test_accessreturnsFALSE,andcheckAccess/check_access return a string with the error message.The functionexpect_access always returns anexpectation.
See Also
Other filesystem:checkDirectoryExists(),checkFileExists(),checkPathForOutput()
Examples
# 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
Description
Check if an argument is an array
Usage
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))Arguments
x | [ |
mode | [ |
any.missing | [ |
d | [ |
min.d | [ |
max.d | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertArray/assert_array returnx invisibly, whereascheckArray/check_array andtestArray/test_array returnTRUE.If the check is not successful,assertArray/assert_arraythrows an error message,testArray/test_arrayreturnsFALSE,andcheckArray/check_array return a string with the error message.The functionexpect_array always returns anexpectation.
See Also
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()
Examples
checkArray(array(1:27, dim = c(3, 3, 3)), d = 3)Check that an argument is an atomic vector
Description
For the definition of “atomic”, seeis.atomic.
Note that 'NULL' is recognized as a valid atomic value, as in R versions up to version 4.3.x.For details, seehttps://stat.ethz.ch/pipermail/r-devel/2023-September/082892.html.
Usage
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))Arguments
x | [ |
any.missing | [ |
all.missing | [ |
len | [ |
min.len | [ |
max.len | [ |
unique | [ |
names | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertAtomic/assert_atomic returnx invisibly, whereascheckAtomic/check_atomic andtestAtomic/test_atomic returnTRUE.If the check is not successful,assertAtomic/assert_atomicthrows an error message,testAtomic/test_atomicreturnsFALSE,andcheckAtomic/check_atomic return a string with the error message.The functionexpect_atomic always returns anexpectation.
See Also
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()
Examples
testAtomic(letters, min.len = 1L, any.missing = FALSE)Check that an argument is an atomic vector
Description
An atomic vector is defined slightly different from specifications inis.atomic andis.vector:An atomic vector is eitherlogical,integer,numeric,complex,character orraw and can have any attributes except adimension attribute (like matrices).I.e., afactor is an atomic vector, but a matrix orNULL are not.In short, this is basically equivalent tois.atomic(x) && !is.null(x) && is.null(dim(x)).
Usage
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))Arguments
x | [ |
any.missing | [ |
all.missing | [ |
len | [ |
min.len | [ |
max.len | [ |
unique | [ |
names | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertAtomicVector/assert_atomic_vector returnx invisibly, whereascheckAtomicVector/check_atomic_vector andtestAtomicVector/test_atomic_vector returnTRUE.If the check is not successful,assertAtomicVector/assert_atomic_vectorthrows an error message,testAtomicVector/test_atomic_vectorreturnsFALSE,andcheckAtomicVector/check_atomic_vector return a string with the error message.The functionexpect_atomic_vector always returns anexpectation.
See Also
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()
Examples
testAtomicVector(letters, min.len = 1L, any.missing = FALSE)Check if an argument is a vector of type character
Description
To check for scalar strings, seecheckString.
Usage
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))Arguments
x | [ |
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 | [ |
Details
This function does not distinguish betweenNA,NA_integer_,NA_real_,NA_complex_NA_character_ andNaN.
Value
Depending on the function prefix:If the check is successful, the functionsassertCharacter/assert_character returnx invisibly, whereascheckCharacter/check_character andtestCharacter/test_character returnTRUE.If the check is not successful,assertCharacter/assert_characterthrows an error message,testCharacter/test_characterreturnsFALSE,andcheckCharacter/check_character return a string with the error message.The functionexpect_character always returns anexpectation.
See Also
Other basetypes:checkArray(),checkAtomic(),checkAtomicVector(),checkComplex(),checkDataFrame(),checkDate(),checkDouble(),checkEnvironment(),checkFactor(),checkFormula(),checkFunction(),checkInteger(),checkIntegerish(),checkList(),checkLogical(),checkMatrix(),checkNull(),checkNumeric(),checkPOSIXct(),checkRaw(),checkVector()
Examples
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
Description
Check if an object is an element of a given set
Usage
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))Arguments
x | [ |
choices | [ |
null.ok | [ |
fmatch | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertChoice/assert_choice returnx invisibly, whereascheckChoice/check_choice andtestChoice/test_choice returnTRUE.If the check is not successful,assertChoice/assert_choicethrows an error message,testChoice/test_choicereturnsFALSE,andcheckChoice/check_choice return a string with the error message.The functionexpect_choice always returns anexpectation.
Note
The objectx must be of the same type as the set w.r.t.typeof.Integers and doubles are both treated as numeric.
See Also
Other set:checkDisjunct(),checkPermutation(),checkSetEqual(),checkSubset()
Examples
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
Description
Check the class membership of an argument
Usage
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))Arguments
x | [ |
classes | [ |
ordered | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertClass/assert_class returnx invisibly, whereascheckClass/check_class andtestClass/test_class returnTRUE.If the check is not successful,assertClass/assert_classthrows an error message,testClass/test_classreturnsFALSE,andcheckClass/check_class return a string with the error message.The functionexpect_class always returns anexpectation.
See Also
Other attributes:checkMultiClass(),checkNamed(),checkNames()
Other classes:checkMultiClass(),checkR6()
Examples
# Create an object with classes "foo" and "bar"x = 1class(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
Description
Check if an argument is a vector of type complex
Usage
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))Arguments
x | [ |
any.missing | [ |
all.missing | [ |
len | [ |
min.len | [ |
max.len | [ |
unique | [ |
names | [ |
typed.missing | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Details
This function does not distinguish betweenNA,NA_integer_,NA_real_,NA_complex_NA_character_ andNaN.
Value
Depending on the function prefix:If the check is successful, the functionsassertComplex/assert_complex returnx invisibly, whereascheckComplex/check_complex andtestComplex/test_complex returnTRUE.If the check is not successful,assertComplex/assert_complexthrows an error message,testComplex/test_complexreturnsFALSE,andcheckComplex/check_complex return a string with the error message.The functionexpect_complex always returns anexpectation.
See Also
Other basetypes:checkArray(),checkAtomic(),checkAtomicVector(),checkCharacter(),checkDataFrame(),checkDate(),checkDouble(),checkEnvironment(),checkFactor(),checkFormula(),checkFunction(),checkInteger(),checkIntegerish(),checkList(),checkLogical(),checkMatrix(),checkNull(),checkNumeric(),checkPOSIXct(),checkRaw(),checkVector()
Examples
testComplex(1)testComplex(1+1i)Check if an argument is a count
Description
A count is defined as non-negative integerish value.
Usage
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))Arguments
x | [ |
na.ok | [ |
positive | [ |
tol | [ |
null.ok | [ |
coerce | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Details
This function does not distinguish betweenNA,NA_integer_,NA_real_,NA_complex_NA_character_ andNaN.
Value
Depending on the function prefix:If the check is successful, the functionsassertCount/assert_count returnx invisibly, whereascheckCount/check_count andtestCount/test_count returnTRUE.If the check is not successful,assertCount/assert_countthrows an error message,testCount/test_countreturnsFALSE,andcheckCount/check_count return a string with the error message.The functionexpect_count always returns anexpectation.
Note
To perform an assertion and then convert to integer, useasCount.assertCount will not convert numerics to integer.
See Also
Other scalars:checkFlag(),checkInt(),checkNumber(),checkScalar(),checkScalarNA(),checkString()
Examples
testCount(1)testCount(-1)Check if an argument is a data frame
Description
Check if an argument is a data frame
Usage
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))Arguments
x | [ |
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 | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertDataFrame/assert_data_frame returnx invisibly, whereascheckDataFrame/check_data_frame andtestDataFrame/test_data_frame returnTRUE.If the check is not successful,assertDataFrame/assert_data_framethrows an error message,testDataFrame/test_data_framereturnsFALSE,andcheckDataFrame/check_data_frame return a string with the error message.The functionexpect_data_frame always returns anexpectation.
See Also
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()
Examples
testDataFrame(iris)testDataFrame(iris, types = c("numeric", "factor"), min.rows = 1, col.names = "named")Check if an argument is a data table
Description
Check if an argument is a data table
Usage
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))Arguments
x | [ |
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 | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertDataTable/assert_data_table returnx invisibly, whereascheckDataTable/check_data_table andtestDataTable/test_data_table returnTRUE.If the check is not successful,assertDataTable/assert_data_tablethrows an error message,testDataTable/test_data_tablereturnsFALSE,andcheckDataTable/check_data_table return a string with the error message.The functionexpect_data_table always returns anexpectation.
See Also
Other compound:checkArray(),checkDataFrame(),checkMatrix(),checkTibble()
Examples
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)Check that an argument is a Date
Description
Checks that an object is of classDate.
Usage
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))Arguments
x | [ |
lower | [ |
upper | [ |
any.missing | [ |
all.missing | [ |
len | [ |
min.len | [ |
max.len | [ |
unique | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertAtomic/assert_atomic returnx invisibly, whereascheckAtomic/check_atomic andtestAtomic/test_atomic returnTRUE.If the check is not successful,assertAtomic/assert_atomicthrows an error message,testAtomic/test_atomicreturnsFALSE,andcheckAtomic/check_atomic return a string with the error message.The functionexpect_atomic always returns anexpectation.
See Also
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
Description
Check for existence and access rights of directories
Usage
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))Arguments
x | [ |
access | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertDirectoryExists/assert_directory_exists returnx invisibly, whereascheckDirectoryExists/check_directory_exists andtestDirectoryExists/test_directory_exists returnTRUE.If the check is not successful,assertDirectoryExists/assert_directory_existsthrows an error message,testDirectoryExists/test_directory_existsreturnsFALSE,andcheckDirectoryExists/check_directory_exists return a string with the error message.The functionexpect_directory_exists always returns anexpectation.
Note
The functions without the suffix “exists” are deprecated and will be removedfrom the package in a future version due to name clashes.
See Also
Other filesystem:checkAccess(),checkFileExists(),checkPathForOutput()
Examples
# 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
Description
Check if an argument is disjunct from a given set
Usage
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))Arguments
x | [ |
y | [ |
fmatch | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertDisjunct/assert_disjunct returnx invisibly, whereascheckDisjunct/check_disjunct andtestDisjunct/test_disjunct returnTRUE.If the check is not successful,assertDisjunct/assert_disjunctthrows an error message,testDisjunct/test_disjunctreturnsFALSE,andcheckDisjunct/check_disjunct return a string with the error message.The functionexpect_disjunct always returns anexpectation.
Note
The objectx must be of the same type as the set w.r.t.typeof.Integers and doubles are both treated as numeric.
See Also
Other set:checkChoice(),checkPermutation(),checkSetEqual(),checkSubset()
Examples
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
Description
Check that an argument is a vector of type double
Usage
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))Arguments
x | [ |
lower | [ |
upper | [ |
finite | [ |
any.missing | [ |
all.missing | [ |
len | [ |
min.len | [ |
max.len | [ |
unique | [ |
sorted | [ |
names | [ |
typed.missing | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Details
This function does not distinguish betweenNA,NA_integer_,NA_real_,NA_complex_NA_character_ andNaN.
Value
Depending on the function prefix:If the check is successful, the functionsassertDouble/assert_double returnx invisibly, whereascheckDouble/check_double andtestDouble/test_double returnTRUE.If the check is not successful,assertDouble/assert_doublethrows an error message,testDouble/test_doublereturnsFALSE,andcheckDouble/check_double return a string with the error message.The functionexpect_double always returns anexpectation.
See Also
Other basetypes:checkArray(),checkAtomic(),checkAtomicVector(),checkCharacter(),checkComplex(),checkDataFrame(),checkDate(),checkEnvironment(),checkFactor(),checkFormula(),checkFunction(),checkInteger(),checkIntegerish(),checkList(),checkLogical(),checkMatrix(),checkNull(),checkNumeric(),checkPOSIXct(),checkRaw(),checkVector()
Examples
testDouble(1)testDouble(1L)testDouble(1, min.len = 1, lower = 0)Check if an argument is an environment
Description
Check if an argument is an environment
Usage
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))Arguments
x | [ |
contains | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertEnvironment/assert_environment returnx invisibly, whereascheckEnvironment/check_environment andtestEnvironment/test_environment returnTRUE.If the check is not successful,assertEnvironment/assert_environmentthrows an error message,testEnvironment/test_environmentreturnsFALSE,andcheckEnvironment/check_environment return a string with the error message.The functionexpect_environment always returns anexpectation.
See Also
Other basetypes:checkArray(),checkAtomic(),checkAtomicVector(),checkCharacter(),checkComplex(),checkDataFrame(),checkDate(),checkDouble(),checkFactor(),checkFormula(),checkFunction(),checkInteger(),checkIntegerish(),checkList(),checkLogical(),checkMatrix(),checkNull(),checkNumeric(),checkPOSIXct(),checkRaw(),checkVector()
Examples
ee = as.environment(list(a = 1))testEnvironment(ee)testEnvironment(ee, contains = "a")Check if an argument is FALSE
Description
Simply checks if an argument isFALSE.
Usage
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)Arguments
x | [ |
na.ok | [ |
.var.name | [ |
add | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertFALSE./assert_false. returnx invisibly, whereascheckFALSE./check_false. andtestFALSE./test_false. returnTRUE.If the check is not successful,assertFALSE./assert_false.throws an error message,testFALSE./test_false.returnsFALSE,andcheckFALSE./check_false. return a string with the error message.The functionexpect_false. always returns anexpectation.
Examples
testFALSE(FALSE)testFALSE(TRUE)Check if an argument is a factor
Description
Check if an argument is a factor
Usage
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))Arguments
x | [ |
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 | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertFactor/assert_factor returnx invisibly, whereascheckFactor/check_factor andtestFactor/test_factor returnTRUE.If the check is not successful,assertFactor/assert_factorthrows an error message,testFactor/test_factorreturnsFALSE,andcheckFactor/check_factor return a string with the error message.The functionexpect_factor always returns anexpectation.
See Also
Other basetypes:checkArray(),checkAtomic(),checkAtomicVector(),checkCharacter(),checkComplex(),checkDataFrame(),checkDate(),checkDouble(),checkEnvironment(),checkFormula(),checkFunction(),checkInteger(),checkIntegerish(),checkList(),checkLogical(),checkMatrix(),checkNull(),checkNumeric(),checkPOSIXct(),checkRaw(),checkVector()
Examples
x = factor("a", levels = c("a", "b"))testFactor(x)testFactor(x, empty.levels.ok = FALSE)Check existence and access rights of files
Description
Check existence and access rights of files
Usage
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))Arguments
x | [ |
access | [ |
extension | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertFileExists/assert_file_exists returnx invisibly, whereascheckFileExists/check_file_exists andtestFileExists/test_file_exists returnTRUE.If the check is not successful,assertFileExists/assert_file_existsthrows an error message,testFileExists/test_file_existsreturnsFALSE,andcheckFileExists/check_file_exists return a string with the error message.The functionexpect_file_exists always returns anexpectation.
Note
The functions without the suffix “exists” are deprecated and will be removedfrom the package in a future version due to name clashes.test_file has been unexported already.
See Also
Other filesystem:checkAccess(),checkDirectoryExists(),checkPathForOutput()
Examples
# Check if R's COPYING file is readabletestFileExists(file.path(R.home(), "COPYING"), access = "r")# Check if R's COPYING file is readable and writabletestFileExists(file.path(R.home(), "COPYING"), access = "rw")Check if an argument is a flag
Description
A flag is defined as single logical value.
Usage
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))Arguments
x | [ |
na.ok | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Details
This function does not distinguish betweenNA,NA_integer_,NA_real_,NA_complex_NA_character_ andNaN.
Value
Depending on the function prefix:If the check is successful, the functionsassertFlag/assert_flag returnx invisibly, whereascheckFlag/check_flag andtestFlag/test_flag returnTRUE.If the check is not successful,assertFlag/assert_flagthrows an error message,testFlag/test_flagreturnsFALSE,andcheckFlag/check_flag return a string with the error message.The functionexpect_flag always returns anexpectation.
See Also
Other scalars:checkCount(),checkInt(),checkNumber(),checkScalar(),checkScalarNA(),checkString()
Examples
testFlag(TRUE)testFlag(1)Check if an argument is a formula
Description
Check if an argument is a formula
Usage
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))Arguments
x | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertFormula/assert_formula returnx invisibly, whereascheckFormula/check_formula andtestFormula/test_formula returnTRUE.If the check is not successful,assertFormula/assert_formulathrows an error message,testFormula/test_formulareturnsFALSE,andcheckFormula/check_formula return a string with the error message.The functionexpect_formula always returns anexpectation.
See Also
Other basetypes:checkArray(),checkAtomic(),checkAtomicVector(),checkCharacter(),checkComplex(),checkDataFrame(),checkDate(),checkDouble(),checkEnvironment(),checkFactor(),checkFunction(),checkInteger(),checkIntegerish(),checkList(),checkLogical(),checkMatrix(),checkNull(),checkNumeric(),checkPOSIXct(),checkRaw(),checkVector()
Examples
f = Species ~ Sepal.Length + Sepal.WidthcheckFormula(f)Check if an argument is a function
Description
Check if an argument is a function
Usage
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))Arguments
x | [ |
args | [ |
ordered | [ |
nargs | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertFunction/assert_function returnx invisibly, whereascheckFunction/check_function andtestFunction/test_function returnTRUE.If the check is not successful,assertFunction/assert_functionthrows an error message,testFunction/test_functionreturnsFALSE,andcheckFunction/check_function return a string with the error message.The functionexpect_function always returns anexpectation.
See Also
Other basetypes:checkArray(),checkAtomic(),checkAtomicVector(),checkCharacter(),checkComplex(),checkDataFrame(),checkDate(),checkDouble(),checkEnvironment(),checkFactor(),checkFormula(),checkInteger(),checkIntegerish(),checkList(),checkLogical(),checkMatrix(),checkNull(),checkNumeric(),checkPOSIXct(),checkRaw(),checkVector()
Examples
testFunction(mean)testFunction(mean, args = "x")Check if an argument is a single integerish value
Description
Check if an argument is a single integerish value
Usage
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))Arguments
x | [ |
na.ok | [ |
lower | [ |
upper | [ |
tol | [ |
null.ok | [ |
coerce | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Details
This function does not distinguish betweenNA,NA_integer_,NA_real_,NA_complex_NA_character_ andNaN.
Value
Depending on the function prefix:If the check is successful, the functionsassertInt/assert_int returnx invisibly, whereascheckInt/check_int andtestInt/test_int returnTRUE.If the check is not successful,assertInt/assert_intthrows an error message,testInt/test_intreturnsFALSE,andcheckInt/check_int return a string with the error message.The functionexpect_int always returns anexpectation.
Note
To perform an assertion and then convert to integer, useasInt.assertInt will not convert numerics to integer.
See Also
Other scalars:checkCount(),checkFlag(),checkNumber(),checkScalar(),checkScalarNA(),checkString()
Examples
testInt(1)testInt(-1, lower = 0)Check if an argument is vector of type integer
Description
Check if an argument is vector of type integer
Usage
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))Arguments
x | [ |
lower | [ |
upper | [ |
any.missing | [ |
all.missing | [ |
len | [ |
min.len | [ |
max.len | [ |
unique | [ |
sorted | [ |
names | [ |
typed.missing | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Details
This function does not distinguish betweenNA,NA_integer_,NA_real_,NA_complex_NA_character_ andNaN.
Value
Depending on the function prefix:If the check is successful, the functionsassertInteger/assert_integer returnx invisibly, whereascheckInteger/check_integer andtestInteger/test_integer returnTRUE.If the check is not successful,assertInteger/assert_integerthrows an error message,testInteger/test_integerreturnsFALSE,andcheckInteger/check_integer return a string with the error message.The functionexpect_integer always returns anexpectation.
See Also
Other basetypes:checkArray(),checkAtomic(),checkAtomicVector(),checkCharacter(),checkComplex(),checkDataFrame(),checkDate(),checkDouble(),checkEnvironment(),checkFactor(),checkFormula(),checkFunction(),checkIntegerish(),checkList(),checkLogical(),checkMatrix(),checkNull(),checkNumeric(),checkPOSIXct(),checkRaw(),checkVector()
Examples
testInteger(1L)testInteger(1.)testInteger(1:2, lower = 1, upper = 2, any.missing = FALSE)Check if an object is an integerish vector
Description
An integerish value is defined as value safely convertible to integer.This includes integers and numeric values which sufficiently close to aninteger w.r.t. a numeric tolerance 'tol'.
Usage
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))Arguments
x | [ |
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 | [ |
Details
This function does not distinguish betweenNA,NA_integer_,NA_real_,NA_complex_NA_character_ andNaN.
Value
Depending on the function prefix:If the check is successful, the functionsassertIntegerish/assert_integerish returnx invisibly, whereascheckIntegerish/check_integerish andtestIntegerish/test_integerish returnTRUE.If the check is not successful,assertIntegerish/assert_integerishthrows an error message,testIntegerish/test_integerishreturnsFALSE,andcheckIntegerish/check_integerish return a string with the error message.The functionexpect_integerish always returns anexpectation.
Note
To convert from integerish to integer, useasInteger.
See Also
Other basetypes:checkArray(),checkAtomic(),checkAtomicVector(),checkCharacter(),checkComplex(),checkDataFrame(),checkDate(),checkDouble(),checkEnvironment(),checkFactor(),checkFormula(),checkFunction(),checkInteger(),checkList(),checkLogical(),checkMatrix(),checkNull(),checkNumeric(),checkPOSIXct(),checkRaw(),checkVector()
Examples
testIntegerish(1L)testIntegerish(1.)testIntegerish(1:2, lower = 1L, upper = 2L, any.missing = FALSE)Check if an argument is a list
Description
Check if an argument is a list
Usage
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))Arguments
x | [ |
types | [ |
any.missing | [ |
all.missing | [ |
len | [ |
min.len | [ |
max.len | [ |
unique | [ |
names | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertList/assert_list returnx invisibly, whereascheckList/check_list andtestList/test_list returnTRUE.If the check is not successful,assertList/assert_listthrows an error message,testList/test_listreturnsFALSE,andcheckList/check_list return a string with the error message.The functionexpect_list always returns anexpectation.
Note
Contrary to R'sis.list, objects of typedata.frameandpairlist are not recognized as list.
Missingness is defined here as elements of the list beingNULL, analogously toanyMissing.
The test for uniqueness does differentiate between the different NA types which are built-in in R.This is required to be consistent withunique while checkingscalar missing values. Also see the example.
See Also
Other basetypes:checkArray(),checkAtomic(),checkAtomicVector(),checkCharacter(),checkComplex(),checkDataFrame(),checkDate(),checkDouble(),checkEnvironment(),checkFactor(),checkFormula(),checkFunction(),checkInteger(),checkIntegerish(),checkLogical(),checkMatrix(),checkNull(),checkNumeric(),checkPOSIXct(),checkRaw(),checkVector()
Examples
testList(list())testList(as.list(iris), types = c("numeric", "factor"))# MissingnesstestList(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
Description
Check if an argument is a vector of type logical
Usage
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))Arguments
x | [ |
any.missing | [ |
all.missing | [ |
len | [ |
min.len | [ |
max.len | [ |
unique | [ |
names | [ |
typed.missing | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Details
This function does not distinguish betweenNA,NA_integer_,NA_real_,NA_complex_NA_character_ andNaN.
Value
Depending on the function prefix:If the check is successful, the functionsassertLogical/assert_logical returnx invisibly, whereascheckLogical/check_logical andtestLogical/test_logical returnTRUE.If the check is not successful,assertLogical/assert_logicalthrows an error message,testLogical/test_logicalreturnsFALSE,andcheckLogical/check_logical return a string with the error message.The functionexpect_logical always returns anexpectation.
See Also
Other basetypes:checkArray(),checkAtomic(),checkAtomicVector(),checkCharacter(),checkComplex(),checkDataFrame(),checkDate(),checkDouble(),checkEnvironment(),checkFactor(),checkFormula(),checkFunction(),checkInteger(),checkIntegerish(),checkList(),checkMatrix(),checkNull(),checkNumeric(),checkPOSIXct(),checkRaw(),checkVector()
Examples
testLogical(TRUE)testLogical(TRUE, min.len = 1)Check if an argument is a matrix
Description
Check if an argument is a matrix
Usage
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))Arguments
x | [ |
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 | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertMatrix/assert_matrix returnx invisibly, whereascheckMatrix/check_matrix andtestMatrix/test_matrix returnTRUE.If the check is not successful,assertMatrix/assert_matrixthrows an error message,testMatrix/test_matrixreturnsFALSE,andcheckMatrix/check_matrix return a string with the error message.The functionexpect_matrix always returns anexpectation.
See Also
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()
Examples
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
Description
Check the class membership of an argument
Usage
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))Arguments
x | [ |
classes | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertMultiClass/assert_multi_class returnx invisibly, whereascheckMultiClass/check_multi_class andtestMultiClass/test_multi_class returnTRUE.If the check is not successful,assertMultiClass/assert_multi_classthrows an error message,testMultiClass/test_multi_classreturnsFALSE,andcheckMultiClass/check_multi_class return a string with the error message.The functionexpect_multi_class always returns anexpectation.
See Also
Other attributes:checkClass(),checkNamed(),checkNames()
Other classes:checkClass(),checkR6()
Examples
x = 1class(x) = "bar"checkMultiClass(x, c("foo", "bar"))checkMultiClass(x, c("foo", "foobar"))Check if an argument is named
Description
Check if an argument is named
Usage
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")Arguments
x | [ |
type | [ |
.var.name | [ |
add | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertNamed/assert_named returnx invisibly, whereascheckNamed/check_named andtestNamed/test_named returnTRUE.If the check is not successful,assertNamed/assert_namedthrows an error message,testNamed/test_namedreturnsFALSE,andcheckNamed/check_named return a string with the error message.The functionexpect_named always returns anexpectation.
Note
These function are deprecated and will be removed in a future version.Please usecheckNames instead.
See Also
Other attributes:checkClass(),checkMultiClass(),checkNames()
Examples
x = 1:3testNamed(x, "unnamed")names(x) = letters[1:3]testNamed(x, "unique")Check names to comply to specific rules
Description
Performs various checks on character vectors, usually names.
Usage
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))Arguments
x | [ |
type | [
Note that for zero-length |
subset.of | [ |
must.include | [ |
permutation.of | [ |
identical.to | [ |
disjunct.from | [ |
what | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertNames/assert_names returnx invisibly, whereascheckNames/check_names andtestNames/test_names returnTRUE.If the check is not successful,assertNames/assert_namesthrows an error message,testNames/test_namesreturnsFALSE,andcheckNames/check_names return a string with the error message.The functionexpect_names always returns anexpectation.
See Also
Other attributes:checkClass(),checkMultiClass(),checkNamed()
Examples
x = 1:3testNames(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
Description
Check if an argument is NULL
Usage
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)Arguments
x | [ |
.var.name | [ |
add | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertNull/assert_null returnx invisibly, whereascheckNull/check_null andtestNull/test_null returnTRUE.If the check is not successful,assertNull/assert_nullthrows an error message,testNull/test_nullreturnsFALSE,andcheckNull/check_null return a string with the error message.The functionexpect_null always returns anexpectation.
See Also
Other basetypes:checkArray(),checkAtomic(),checkAtomicVector(),checkCharacter(),checkComplex(),checkDataFrame(),checkDate(),checkDouble(),checkEnvironment(),checkFactor(),checkFormula(),checkFunction(),checkInteger(),checkIntegerish(),checkList(),checkLogical(),checkMatrix(),checkNumeric(),checkPOSIXct(),checkRaw(),checkVector()
Examples
testNull(NULL)testNull(1)Check if an argument is a single numeric value
Description
Check if an argument is a single numeric value
Usage
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))Arguments
x | [ |
na.ok | [ |
lower | [ |
upper | [ |
finite | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Details
This function does not distinguish betweenNA,NA_integer_,NA_real_,NA_complex_NA_character_ andNaN.
Value
Depending on the function prefix:If the check is successful, the functionsassertNumber/assert_number returnx invisibly, whereascheckNumber/check_number andtestNumber/test_number returnTRUE.If the check is not successful,assertNumber/assert_numberthrows an error message,testNumber/test_numberreturnsFALSE,andcheckNumber/check_number return a string with the error message.The functionexpect_number always returns anexpectation.
See Also
Other scalars:checkCount(),checkFlag(),checkInt(),checkScalar(),checkScalarNA(),checkString()
Examples
testNumber(1)testNumber(1:2)Check that an argument is a vector of type numeric
Description
Vectors of storage type “integer” and “double” count as “numeric”, c.f.is.numeric.To explicitly check for real integer or double vectors, seecheckInteger,checkIntegerish orcheckDouble.
Usage
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))Arguments
x | [ |
lower | [ |
upper | [ |
finite | [ |
any.missing | [ |
all.missing | [ |
len | [ |
min.len | [ |
max.len | [ |
unique | [ |
sorted | [ |
names | [ |
typed.missing | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Details
This function does not distinguish betweenNA,NA_integer_,NA_real_,NA_complex_NA_character_ andNaN.
Value
Depending on the function prefix:If the check is successful, the functionsassertNumeric/assert_numeric returnx invisibly, whereascheckNumeric/check_numeric andtestNumeric/test_numeric returnTRUE.If the check is not successful,assertNumeric/assert_numericthrows an error message,testNumeric/test_numericreturnsFALSE,andcheckNumeric/check_numeric return a string with the error message.The functionexpect_numeric always returns anexpectation.
See Also
Other basetypes:checkArray(),checkAtomic(),checkAtomicVector(),checkCharacter(),checkComplex(),checkDataFrame(),checkDate(),checkDouble(),checkEnvironment(),checkFactor(),checkFormula(),checkFunction(),checkInteger(),checkIntegerish(),checkList(),checkLogical(),checkMatrix(),checkNull(),checkPOSIXct(),checkRaw(),checkVector()
Examples
testNumeric(1)testNumeric(1, min.len = 1, lower = 0)Check the operating system
Description
Check the operating system
Usage
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)Arguments
os | [ |
add | [ |
.var.name | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertOS/assert_os returnx invisibly, whereascheckOS/check_os andtestOS/test_os returnTRUE.If the check is not successful,assertOS/assert_osthrows an error message,testOS/test_osreturnsFALSE,andcheckOS/check_os return a string with the error message.The functionexpect_os always returns anexpectation.
Examples
testOS("linux")Check that an argument is a date/time object in POSIXct format
Description
Checks that an object is of classPOSIXct.
Usage
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))Arguments
x | [ |
lower | [ |
upper | [ |
any.missing | [ |
all.missing | [ |
len | [ |
min.len | [ |
max.len | [ |
unique | [ |
sorted | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertAtomic/assert_atomic returnx invisibly, whereascheckAtomic/check_atomic andtestAtomic/test_atomic returnTRUE.If the check is not successful,assertAtomic/assert_atomicthrows an error message,testAtomic/test_atomicreturnsFALSE,andcheckAtomic/check_atomic return a string with the error message.The functionexpect_atomic always returns anexpectation.
See Also
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 a path is suited for creating an output file
Description
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
xexist?Is
dirname(x)writable?
Paths are relative to the current working directory.
Usage
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))Arguments
x | [ |
overwrite | [ |
extension | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertPathForOutput/assert_path_for_output returnx invisibly, whereascheckPathForOutput/check_path_for_output andtestPathForOutput/test_path_for_output returnTRUE.If the check is not successful,assertPathForOutput/assert_path_for_outputthrows an error message,testPathForOutput/test_path_for_outputreturnsFALSE,andcheckPathForOutput/check_path_for_output return a string with the error message.The functionexpect_path_for_output always returns anexpectation.
See Also
Other filesystem:checkAccess(),checkDirectoryExists(),checkFileExists()
Examples
# Can we create a file in the tempdir?testPathForOutput(file.path(tempdir(), "process.log"))Check if the arguments are permutations of each other.
Description
In contrast tocheckSetEqual, the function tests for a truepermutation 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.
Usage
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))Arguments
x | [ |
y | [ |
na.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertPermutation/assert_permutation returnx invisibly, whereascheckPermutation/check_permutation andtestPermutation/test_permutation returnTRUE.If the check is not successful,assertPermutation/assert_permutationthrows an error message,testPermutation/test_permutationreturnsFALSE,andcheckPermutation/check_permutation return a string with the error message.The functionexpect_permutation always returns anexpectation.
Note
The objectx must be of the same type as the set w.r.t.typeof.Integers and doubles are both treated as numeric.
See Also
Other set:checkChoice(),checkDisjunct(),checkSetEqual(),checkSubset()
Examples
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)Check if an argument is an R6 class
Description
Check if an argument is an R6 class
Usage
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))Arguments
x | [ |
classes | [ |
ordered | [ |
cloneable | [ |
public | [ |
private | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertClass/assert_class returnx invisibly, whereascheckClass/check_class andtestClass/test_class returnTRUE.If the check is not successful,assertClass/assert_classthrows an error message,testClass/test_classreturnsFALSE,andcheckClass/check_class return a string with the error message.The functionexpect_class always returns anexpectation.
See Also
Other classes:checkClass(),checkMultiClass()
Examples
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
Description
Check if an argument is a raw vector
Usage
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))Arguments
x | [ |
len | [ |
min.len | [ |
max.len | [ |
names | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertRaw/assert_raw returnx invisibly, whereascheckRaw/check_raw andtestRaw/test_raw returnTRUE.If the check is not successful,assertRaw/assert_rawthrows an error message,testRaw/test_rawreturnsFALSE,andcheckRaw/check_raw return a string with the error message.The functionexpect_raw always returns anexpectation.
See Also
Other basetypes:checkArray(),checkAtomic(),checkAtomicVector(),checkCharacter(),checkComplex(),checkDataFrame(),checkDate(),checkDouble(),checkEnvironment(),checkFactor(),checkFormula(),checkFunction(),checkInteger(),checkIntegerish(),checkList(),checkLogical(),checkMatrix(),checkNull(),checkNumeric(),checkPOSIXct(),checkVector()
Examples
testRaw(as.raw(2), min.len = 1L)Check if an argument is a single atomic value
Description
Check if an argument is a single atomic value
Usage
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))Arguments
x | [ |
na.ok | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Details
This function does not distinguish betweenNA,NA_integer_,NA_real_,NA_complex_NA_character_ andNaN.
Value
Depending on the function prefix:If the check is successful, the functionsassertScalar/assert_scalar returnx invisibly, whereascheckScalar/check_scalar andtestScalar/test_scalar returnTRUE.If the check is not successful,assertScalar/assert_scalarthrows an error message,testScalar/test_scalarreturnsFALSE,andcheckScalar/check_scalar return a string with the error message.The functionexpect_scalar always returns anexpectation.
See Also
Other scalars:checkCount(),checkFlag(),checkInt(),checkNumber(),checkScalarNA(),checkString()
Examples
testScalar(1)testScalar(1:10)Check if an argument is a single missing value
Description
Check if an argument is a single missing value
Usage
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))Arguments
x | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertScalarNA/assert_scalar_na returnx invisibly, whereascheckScalarNA/check_scalar_na andtestScalarNA/test_scalar_na returnTRUE.If the check is not successful,assertScalarNA/assert_scalar_nathrows an error message,testScalarNA/test_scalar_nareturnsFALSE,andcheckScalarNA/check_scalar_na return a string with the error message.The functionexpect_scalar_na always returns anexpectation.
See Also
Other scalars:checkCount(),checkFlag(),checkInt(),checkNumber(),checkScalar(),checkString()
Examples
testScalarNA(1)testScalarNA(NA_real_)testScalarNA(rep(NA, 2))Check if an argument is equal to a given set
Description
Check if an argument is equal to a given set
Usage
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))Arguments
x | [ |
y | [ |
ordered | [ |
fmatch | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertSubset/assert_subset returnx invisibly, whereascheckSubset/check_subset andtestSubset/test_subset returnTRUE.If the check is not successful,assertSubset/assert_subsetthrows an error message,testSubset/test_subsetreturnsFALSE,andcheckSubset/check_subset return a string with the error message.The functionexpect_subset always returns anexpectation.
Note
The objectx must be of the same type as the set w.r.t.typeof.Integers and doubles are both treated as numeric.
See Also
Other set:checkChoice(),checkDisjunct(),checkPermutation(),checkSubset()
Examples
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))Check if an argument is a string
Description
A string is defined as a scalar character vector.To check for vectors of arbitrary length, seecheckCharacter.
Usage
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))Arguments
x | [ |
na.ok | [ |
n.chars | [ |
min.chars | [ |
max.chars | [ |
pattern | [ |
fixed | [ |
ignore.case | [ |
null.ok | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Details
This function does not distinguish betweenNA,NA_integer_,NA_real_,NA_complex_NA_character_ andNaN.
Value
Depending on the function prefix:If the check is successful, the functionsassertString/assert_string returnx invisibly, whereascheckString/check_string andtestString/test_string returnTRUE.If the check is not successful,assertString/assert_stringthrows an error message,testString/test_stringreturnsFALSE,andcheckString/check_string return a string with the error message.The functionexpect_string always returns anexpectation.
See Also
Other scalars:checkCount(),checkFlag(),checkInt(),checkNumber(),checkScalar(),checkScalarNA()
Examples
testString("a")testString(letters)Check if an argument is a subset of a given set
Description
Check if an argument is a subset of a given set
Usage
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))Arguments
x | [ |
choices | [ |
empty.ok | [ |
fmatch | [ |
.var.name | [ |
add | [ |
info | [ |
label | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertSubset/assert_subset returnx invisibly, whereascheckSubset/check_subset andtestSubset/test_subset returnTRUE.If the check is not successful,assertSubset/assert_subsetthrows an error message,testSubset/test_subsetreturnsFALSE,andcheckSubset/check_subset return a string with the error message.The functionexpect_subset always returns anexpectation.
Note
The objectx must be of the same type as the set w.r.t.typeof.Integers and doubles are both treated as numeric.
See Also
Other set:checkChoice(),checkDisjunct(),checkPermutation(),checkSetEqual()
Examples
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 TRUE
Description
Simply checks if an argument isTRUE.
Usage
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)Arguments
x | [ |
na.ok | [ |
.var.name | [ |
add | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertTRUE./assert_true. returnx invisibly, whereascheckTRUE./check_true. andtestTRUE./test_true. returnTRUE.If the check is not successful,assertTRUE./assert_true.throws an error message,testTRUE./test_true.returnsFALSE,andcheckTRUE./check_true. return a string with the error message.The functionexpect_true. always returns anexpectation.
Examples
testTRUE(TRUE)testTRUE(FALSE)Check if an argument is a tibble
Description
Check if an argument is a tibble
Usage
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))Arguments
x | [ |
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 | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertTibble/assert_tibble returnx invisibly, whereascheckTibble/check_tibble andtestTibble/test_tibble returnTRUE.If the check is not successful,assertTibble/assert_tibblethrows an error message,testTibble/test_tibblereturnsFALSE,andcheckTibble/check_tibble return a string with the error message.The functionexpect_tibble always returns anexpectation.
See Also
Other compound:checkArray(),checkDataFrame(),checkDataTable(),checkMatrix()
Examples
library(tibble)x = as_tibble(iris)testTibble(x)testTibble(x, nrow = 150, any.missing = FALSE)Check if an argument is a vector
Description
Check if an argument is a vector
Usage
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)Arguments
x | [ |
strict | [ |
any.missing | [ |
all.missing | [ |
len | [ |
min.len | [ |
max.len | [ |
unique | [ |
names | [ |
null.ok | [ |
.var.name | [ |
add | [ |
Value
Depending on the function prefix:If the check is successful, the functionsassertVector/assert_vector returnx invisibly, whereascheckVector/check_vector andtestVector/test_vector returnTRUE.If the check is not successful,assertVector/assert_vectorthrows an error message,testVector/test_vectorreturnsFALSE,andcheckVector/check_vector return a string with the error message.The functionexpect_vector always returns anexpectation.
See Also
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()
Examples
testVector(letters, min.len = 1L, any.missing = FALSE)Turn a Check into an Assertion
Description
makeAssertion is the internal function used to evaluate the result of acheck and throw an exception if necessary.makeAssertionFunction can be used to automatically create an assertionfunction based on a check function (see example).
Usage
makeAssertion(x, res, var.name, collection)makeAssertionFunction( check.fun, c.fun = NULL, use.namespace = TRUE, coerce = FALSE, env = parent.frame())Arguments
x | [ |
res | [ |
var.name | [ |
collection | [ |
check.fun | [ |
c.fun | [ |
use.namespace | [ |
coerce | [ |
env | [ |
Value
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 afunction.
See Also
Other CustomConstructors:makeExpectation(),makeTest()
Examples
# Simple custom check functioncheckFalse = function(x) if (!identical(x, FALSE)) "Must be FALSE" else TRUE# Create the respective assert functionassertFalse = function(x, .var.name = vname(x), add = NULL) { res = checkFalse(x) makeAssertion(x, res, .var.name, add)}# Alternative: Automatically create such a functionassertFalse = makeAssertionFunction(checkFalse)print(assertFalse)Turn a Check into an Expectation
Description
makeExpectation is the internal function used to evaluate the result of acheck and turn it into anexpectation.makeExceptionFunction can be used to automatically create an expectationfunction based on a check function (see example).
Usage
makeExpectation(x, res, info, label)makeExpectationFunction( check.fun, c.fun = NULL, use.namespace = FALSE, env = parent.frame())Arguments
x | [ |
res | [ |
info | [ |
label | [ |
check.fun | [ |
c.fun | [ |
use.namespace | [ |
env | [ |
Value
makeExpectation invisibly returns the checked object.makeExpectationFunction returns afunction.
See Also
Other CustomConstructors:makeAssertion(),makeTest()
Examples
# Simple custom check functioncheckFalse = function(x) if (!identical(x, FALSE)) "Must be FALSE" else TRUE# Create the respective expect functionexpect_false = function(x, info = NULL, label = vname(x)) { res = checkFalse(x) makeExpectation(x, res, info = info, label = label)}# Alternative: Automatically create such a functionexpect_false = makeExpectationFunction(checkFalse)print(expect_false)Turn a Check into a Test
Description
makeTest is the internal function used to evaluate the result of acheck and throw an exception if necessary.This function is currently only a stub and just callsisTRUE.makeTestFunction can be used to automatically create an assertionfunction based on a check function (see example).
Usage
makeTest(res)makeTestFunction(check.fun, c.fun = NULL, env = parent.frame())Arguments
res | [ |
check.fun | [ |
c.fun | [ |
env | [ |
Value
makeTest returnsTRUE if the check is successful andFALSE otherwise.makeTestFunction returns afunction.
See Also
Other CustomConstructors:makeAssertion(),makeExpectation()
Examples
# Simple custom check functioncheckFalse = function(x) if (!identical(x, FALSE)) "Must be FALSE" else TRUE# Create the respective test functiontestFalse = function(x) { res = checkFalse(x) makeTest(res)}# Alternative: Automatically create such a functiontestFalse = makeTestFunction(checkFalse)print(testFalse)Partial Argument Matching
Description
This is an extensions tomatch.arg with support forAssertCollection.The behavior is very similar tomatch.arg, except thatNULL is nota valid value forx.
Usage
matchArg(x, choices, several.ok = FALSE, .var.name = vname(x), add = NULL)Arguments
x | [ |
choices | [ |
several.ok | [ |
.var.name | [ |
add | [ |
Value
Subset ofchoices.
Examples
matchArg("k", choices = c("kendall", "pearson"))Quick argument checks on (builtin) R types
Description
The provided functions parse rules which allow to express some of the mostfrequent argument checks by typing just a few letters.
Usage
qassert(x, rules, .var.name = vname(x))qtest(x, rules)qexpect(x, rules, info = NULL, label = vname(x))Arguments
x | [ |
rules | [ |
.var.name | [ |
info | [ |
label | [ |
Details
The rule is specified in up to three parts.
Class and missingness check.The first letter is an abbreviation for the class. If it isprovided 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 NULLelement.[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
NaNandNA. Infinite values are not treated as missing, butcan 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 orpositive infinite bound, respectively.By definition[0,]containsInf, 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.
Value
qassert throws anR exception if objectx doesnot comply to at least one of therules and returns the tested object invisiblyotherwise.qtest behaves the same way but returnsFALSE if none of therules comply.qexpect is intended to be inside the unit test frameworktestthat andreturns anexpectation.
Note
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.
See Also
qtestr andqassertr for efficient checksof list elements and data frame columns.
Examples
# logical of length 1qtest(NA, "b1")# logical of length 1, NA not allowedqtest(NA, "B1")# logical of length 0 or 1, NA not allowedqtest(TRUE, "B?")# numeric with length > 0qtest(runif(10), "n+")# integer with length > 0, NAs not allowed, all integers >= 0 and < Infqtest(1:3, "I+[0,)")# either an emtpy list or a character vector with <=5 elementsqtest(1, c("l0", "s<=5"))# data frame with at least one column and no missing value in any columnqtest(iris, "D+")Quick recursive arguments checks on lists and data frames
Description
These functions are the tuned counterparts ofqtest,qassert andqexpect tailored for recursivechecks of list elements or data frame columns.
Usage
qassertr(x, rules, .var.name = vname(x))qtestr(x, rules, depth = 1L)qexpectr(x, rules, info = NULL, label = vname(x))Arguments
x | [ |
rules | [ |
.var.name | [ |
depth | [ |
info | [ |
label | [ |
Value
Seeqassert.
See Also
Examples
# 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 characterqtestr(list(a = 1:3, b = rnorm(1), c = letters), c("N+", "S+"))Select Backend for Unit Tests
Description
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" unlessthe"tinytest"'s namespace is loaded.
Usage
register_test_backend(name)Arguments
name | [ |
Value
NULL (invisibly).
Lookup a variable name
Description
Tries to heuristically determine the variable name ofx in the parent framewith a combination ofdeparse andsubstitute.Used for checkmate's error messages.
Usage
vname(x)Arguments
x | [ |
Value
[character(1)] Variable name.
Get the index of the first/last TRUE
Description
A quick C implementation for “which.first” (head(which(x), 1)) and“which.last” (tail(which(x), 1)).
Usage
wf(x, use.names = TRUE)wl(x, use.names = TRUE)Arguments
x | [ |
use.names | [ |
Value
[integer(1) |integer(0)].Returns the index of the first/lastTRUE value inx oran empty integer vector if none is found. NAs are ignored.
Examples
wf(c(FALSE, TRUE))wl(c(FALSE, FALSE))wf(NA)