This function is adapted from gargle's abort_bad_class function. It provides an informative error message indicating the object and the class it must be for the function to work properly.

cls_abort(object, expected_class)

Arguments

object

The object whose class should be checked.

expected_class

A character vector of expected (or allowed) classes.

Value

NA; triggers an error.

Examples

if (interactive()) { is_df <- function(x) { if (is.data.frame(x)) { cls_abort(mtcars, expected_class = c("character", "numeric")) } } is_df(mtcars) }