check_class: Check the class of an function input to a parent function

View source: R/utils.R

check_classR Documentation

Check the class of an function input to a parent function

Description

This function checks that the class of an input to a parent function is appropriate. If not, the function either produces a helpful error message or returns a warning.

Usage

check_class(
  arg = deparse(substitute(input)),
  input,
  if_class = NULL,
  to_class,
  type = "stop",
  coerce_input
)

Arguments

arg

A character string which defines the argument of the parent function.

input

The input to an argument of a parent function.

if_class

(optional) A character vector of classes of object. If supplied, the function will only proceed to check the class of the object if the class(input) is one of if_class. This is useful if check_class() is implemented in a loop.

to_class

The required class of the input.

type

A character which specifies whether to return an error ("stop") or a warning ("warning").

coerce_input

A function used to coerce input to the correct object type, if type = "warning".

Value

The function checks the class of the input. If the class is not the same as required by the parent function (i.e., as specified by class), the function returns a helpful error message, or a warning and an object whose class has been coerced to the correct class.

Author(s)

Edward Lavender


edwardlavender/fvcom.tbx documentation built on Nov. 26, 2022, 10:28 p.m.