R: Check if an argument is a bit vector

checkBit {checkmate} | R Documentation

## Check if an argument is a bit vector

### Description

Check if an argument is a bit vector

### Usage

    checkBit(x, len = NULL, min.len = NULL, max.len = NULL,
      min.0 = NULL, min.1 = NULL, null.ok = FALSE)

    check_bit(x, len = NULL, min.len = NULL, max.len = NULL,
      min.0 = NULL, min.1 = NULL, null.ok = FALSE)

    assertBit(x, len = NULL, min.len = NULL, max.len = NULL,
      min.0 = NULL, min.1 = NULL, null.ok = FALSE,
      .var.name = vname(x), add = NULL)

    assert_bit(x, len = NULL, min.len = NULL, max.len = NULL,
      min.0 = NULL, min.1 = NULL, null.ok = FALSE,
      .var.name = vname(x), add = NULL)

    testBit(x, len = NULL, min.len = NULL, max.len = NULL,
      min.0 = NULL, min.1 = NULL, null.ok = FALSE)

    test_bit(x, len = NULL, min.len = NULL, max.len = NULL,
      min.0 = NULL, min.1 = NULL, null.ok = FALSE)

    expect_bit(x, len = NULL, min.len = NULL, max.len = NULL,
      min.0 = NULL, min.1 = NULL, null.ok = FALSE, info = NULL,
      label = vname(x))

### Arguments

`x` | [any] Object to check.
`len` | [`integer(1)`] Exact expected length of `x`.
`min.len` | [`integer(1)`] Minimal length of `x`.
`max.len` | [`integer(1)`] Maximal length of `x`.
`min.0` | [`integer(1)`] Minimum number of elements being “0”/`FALSE`/off.
`min.1` | [`integer(1)`] Minimum number of elements being “1”/`TRUE`/on.
`null.ok` | [`logical(1)`] If set to `TRUE`, `x` may also be `NULL`. In this case only a type check of `x` is performed, all additional checks are disabled.
`.var.name` | [`character(1)`] Name of the checked object to print in assertions. Defaults to the heuristic implemented in `vname`.
`add` | [`AssertCollection`] Collection to store assertion messages. See `AssertCollection`.
`info` | [character(1)] Extra information to be included in the message for the testthat reporter. See `expect_that`.
`label` | [`character(1)`] Name of the checked object to print in messages. Defaults to the heuristic implemented in `vname`.

### Value

Depending on the function prefix: If the check is successful, the functions `assertBit`/`assert_bit` return `x` invisibly, whereas `checkBit`/`check_bit` and `testBit`/`test_bit` return `TRUE`. If the check is not successful, `assertBit`/`assert_bit` throws an error message, `testBit`/`test_bit` returns `FALSE`, and `checkBit` returns a string with the error message. The function `expect_bit` always returns an `expectation`.

### Examples

    library(bit)
    x = as.bit(replace(logical(10), sample(10, 5), TRUE))
    testBit(x, len = 10, min.0 = 1)

[Package checkmate version 1.9.4 Index]