Enforce parameter types (logical, character, etc.).

enforce_type(object, admissible_types, function_name,
  name = deparse(substitute(object)))

Arguments

object

ANY. An R object to enforce types on.

admissible_types

character. A character vector of allowed types.

function_name

character. The function this enforcement is occurring in, for error messages.

name

character. The name of the parameter whose type is being enforced. By default, the string expression passed in to the first argument, object.

Value

Nothing, but error if the type does not match.

Examples

not_run({ x <- 1 enforce_type(x, "logical", "myfunction") # Will call stop() with the following error: # "In 'myfunction', the 'x' parameter must be a character; instead, I got # a logical. })