check_enum: Check if value is in set of allowed values

View source: R/check.R

check_enumR Documentation

Check if value is in set of allowed values

Description

Checks if a value is in a set of allowed values, and throws an error if not.

Usage

check_enum(x, allowed_values, arg_name = deparse(substitute(x)))

Arguments

x

Value to check.

allowed_values

Vector of allowed values.

arg_name

Character: Name of the variable for error messages.

Value

Called for side effects. Throws an error if x is not in allowed_values, returns x invisibly otherwise.

Author(s)

EDG

Examples

check_enum("apple", c("apple", "banana", "cherry"))
# Throws error:
try(check_enum("granola", c("croissant", "bagel", "scramble")))

rtemis.core documentation built on April 22, 2026, 1:11 a.m.