# Create an enum type for colors
Colors <- enum("red", "green", "blue")
# Create enum objects
my_color <- Colors("red")
print(my_color) # Output: Enum: red
# Trying to create an enum with an invalid value will raise an error
try(Colors("yellow"))
# Enums can be used in interfaces
ColoredShape <- interface(
shape = character,
color = Colors
)
my_shape <- ColoredShape(shape = "circle", color = "red")
# Modifying enum values
my_shape$color$value <- "blue" # This is valid
try(my_shape$color$value <- "yellow") # This will raise an error
Run the code above in your browser using DataLab