This helper function builds an enum type using the provided arguments.
1 2 3
Vector with all allowed values and (optionally) the enum names as names of the vector elements.
Vector of character strings containing the names that correspond to the allowed values
If the names are neither provided in the allowed values nor in the parameter 'value.names'
the enum values are taken as names.
Duplicated names will be made unique only if the parameter
Vector with more detailled descriptive information for each enum value
TRUE to convert invalid characters into syntacically allowed names
and make duplicated names unique (by appending a number).
FALSE leaves value names like they are. To use enum names that contain invalid
characters you have to quote them, e. g.
Setting the enum names via the
value.names parameter is mainly useful to load the elements
of an enum from a data base or config file (e. g. CSV file) to create an enum type.
Since the returned enumeration object is also a
list you can also use it like a list,
e. g. accessing single enum values by using the $ operator (
This is the reason for a
list instead of an atomic vector as internal representation.
An object of class "enumeration" that represents an enumeration via a list with named elements
1 2 3 4 5 6 7 8 9 10
# This is the easiest way to create an enumeration if the enum values are not important DRINKS <- create.enum(c("COFFEE", "TEA", "SOFT DRINK")) # This is the most intuitive way of creating an enumeration COLOR.ENUM <- create.enum(c(BLUE = 1L, RED = 2L, BLACK = 3L)) COLOR.ENUM <- create.enum(c(1L, 2L, 3L), c("BLUE", "RED", "BLACK")) # returns an enumeration type that internally is constructed similar to this: # COLOR.ENUM <- list(BLUE = 1L, RED = 2L, BLACK = 3L)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.