enum: Define an enumerated list

View source: R/enum.R

enumR Documentation

Define an enumerated list

Description

Create an enumeration to be used instead of arbitrary values in code. In some languages (C, C++, Python, etc.), enum (or enumeration) is a data type that consists of integer constants and is ideal in contexts where a variable can take on only one of a limited set of possible values (e.g. day of the week). Since R programming language natively doesn't support enumeration, the current function provides a way to create them using lists.

Usage

enum(enumValues)

Arguments

enumValues

A vector or a list of comma-separated constants to use for creating the enum. Optionally, these can be named constants.

Value

An enumerated list.

See Also

Other enumeration-helpers: enumGetKey(), enumGetValue(), enumHasKey(), enumKeys(), enumPut(), enumRemove(), enumValues()

Examples

# Without predefined values
Color <- enum(c("Red", "Blue", "Green"))
Color
myColor <- Color$Red
myColor

# With predefined values
Symbol <- enum(c(Diamond = 1, Triangle = 2, Circle = 2))
Symbol

mySymbol <- Symbol$Diamond
mySymbol

ospsuite.utils documentation built on March 18, 2022, 6:44 p.m.