check_class {labelr}R Documentation

Determine If Vector Belongs to Any of Specified Classes

Description

check_class determines whether a vector's class is among those specified.

Usage

check_class(
  x,
  classes = c("numeric", "integer", "logical", "character", "factor", "ordered"),
  strict = TRUE
)

Arguments

x

the vector to check against specified classes.

classes

a character vector of classes against which x is checked.

strict

If TRUE, all of x's classes must be among those specified in the classes argument. If FALSE, at least one but not necessarily all of x's classes must be among those specified in the classes argument.

Details

By default (strict = TRUE), if a vector is of multiple classes, all of its classes must be among those specified via the classes argument.

Value

a 1L logical vector indicating whether x's class is found among those passed to the classes argument.

Examples

check_class(mtcars$mpg) # TRUE
check_class(mtcars$mpg, classes = c("numeric", "factor")) # TRUE
check_class(iris$Species) # TRUE
check_class(iris$Species, classes = c("logical", "numeric")) # FALSE
check_class(mtcars$mpg, classes = c("logical", "character", "factor")) # FALSE

[Package labelr version 0.1.5 Index]