checkFactor {checkmate} | R Documentation |
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 |
[any] |
levels |
[ |
ordered |
[ |
empty.levels.ok |
[ |
any.missing |
[ |
all.missing |
[ |
len |
[ |
min.len |
[ |
max.len |
[ |
n.levels |
[ |
min.levels |
[ |
max.levels |
[ |
unique |
[ |
names |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Value
Depending on the function prefix:
If the check is successful, the functions
assertFactor
/assert_factor
return
x
invisibly, whereas
checkFactor
/check_factor
and
testFactor
/test_factor
return
TRUE
.
If the check is not successful,
assertFactor
/assert_factor
throws an error message,
testFactor
/test_factor
returns FALSE
,
and checkFactor
/check_factor
return a string with the error message.
The function expect_factor
always returns an
expectation
.
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)