R语言【checkmate】——checkChoice,assertChoice,testChoice,expectChoice检查对象是否是给定集合的一个元素

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))

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ALittleHigh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值