checkmate 2.3.1
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】:【any】,检查的对象。
参数【choices】:【atomic】,接受值集合。
参数【null.ok】:【logical(1)】,设置为TRUE,x可以是null。在这种情况下,只对 x 进行类型检查,所有其他检查都被禁用。
参数【fmatch】:【logical(1)】,使用 fastmatch 软件包中 fmatch 实现的设置操作。如果没有安装 fastmatch,则会自动退回到 match: 会添加一个哈希表作为属性,在后续调用中使用。
参数【.var.name】:【character(1)】,要在断言中打印的已校验对象的名称。默认使用 vname 中的启发式。
参数【add】:【AssertCollection】,用于存储断言信息的集合。请参阅 AssertCollection。
参数【info】:【character(1)】,包含在 testthat 报告信息中的额外信息。请参阅 expect_that。
参数【label】:【character(1)】,要在信息中打印的被校验对象的名称。默认使用 vname 中的启发式方法。
Value
取决于功能前缀:
如果检查成功,函数 assertChoice/assert_choice 隐式返回 x,而 checkChoice/check_choice 和 testChoice/test_choice 返回 TRUE。
如果检查不成功,assertChoice/assert_choice 会抛出错误信息,testChoice/test_choice 返回 FALSE,而 checkChoice/check_choice 则返回一个包含错误信息的字符串。
函数 expect_choice 总是返回一个期望值。
Note
对象 x 必须与集合的 typeof 类型相同。整数和双数都被视为数值。
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))