R: Check the class membership of an argument

checkMultiClass {checkmate} | R Documentation

## 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` | [any] Object to check.
`classes` | [`character`] Class names to check for inheritance with `inherits`. `x` must inherit from any of the specified classes.
`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 `assertMultiClass`/`assert_multi_class` return `x` invisibly, whereas `checkMultiClass`/`check_multi_class` and `testMultiClass`/`test_multi_class` return `TRUE`. If the check is not successful, `assertMultiClass`/`assert_multi_class` throws an error message, `testMultiClass`/`test_multi_class` returns `FALSE`, and `checkMultiClass` returns a string with the error message. The function `expect_multi_class` always returns an `expectation`.

### See Also

Other attributes: `checkClass()`, `checkNamed()`, `checkNames()`

Other classes: `checkClass()`, `checkR6()`

### Examples

    x = 1
    class(x) = "bar"
    checkMultiClass(x, c("foo", "bar"))
    checkMultiClass(x, c("foo", "foobar"))

[Package checkmate version 2.0.0 Index]