cls_abort: Abort Classes with Informative Message

Description Usage Arguments Value Examples

View source: R/func_classes.R

Description

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.

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
if (interactive()) {

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

  is_df(mtcars)

}

jdtrat/jdtools documentation built on Dec. 20, 2021, 10:05 p.m.