enum: enum

View source: R/enums.R

enumR Documentation

enum

Description

Create enumeration pseudo type as S3 'enum' class from a list of named arguments

Usage

enum(...)

Arguments

...

One or more named arguments all of the same type. Alternatively it can be one single list or atomic vector.

Details

'enum()' will try to coerce values to integer and throw an error if that fails. The consequence of this that it will also fail when a list/vector is not the first argument. If a list/vector is indeed the first argument all remaining arguments will be ignored.

Value

A named atomic vector of class 'enum'

Examples

myEnum <- enum(a=1, b=3, c=5)
inEnum(3, myEnum)   # TRUE
inEnum("b", myEnum) # TRUE
inEnum(2, myEnum)   # FALSE, however ...
inEnum(myEnum[3], myEnum)   # TRUE
inEnum(myEnum["c"], myEnum) # TRUE

enum(LETTERS[1:3])

SigurdJanson/plainEnum documentation built on Aug. 27, 2022, 1:40 a.m.