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)
object | The object whose class should be checked. |
---|---|
expected_class | A character vector of expected (or allowed) classes. |
NA; triggers an error.
if (interactive()) { is_df <- function(x) { if (is.data.frame(x)) { cls_abort(mtcars, expected_class = c("character", "numeric")) } } is_df(mtcars) }