Introduction.RmdThis vignette will introduce you to basic functionalities of enumeR package.
First we create some enum_type object. It represents a class with finite number of possible values - similliar to enums from other languages like C++ or Java. During construction of an object besides names of values you can specify values of own fields that will be kept inside values. For example:
season_of_year <- enum_type("season_of_year",
c("SPRING", "SUMMER", "AUTUMN", "WINTER"),
min_temperature = c(-13, 7, -6, -20),
max_temperature = c(20, 32, 18, 12))
print(season_of_year)
#> Enum type: season_of_year
#>
#> Values:
#> 1 : SPRING
#> 2 : SUMMER
#> 3 : AUTUMN
#> 4 : WINTER
#> $SPRING
#> NULL
#>
#> $SUMMER
#> NULL
#>
#> $AUTUMN
#> NULL
#>
#> $WINTER
#> NULLNow you can access values of this type:
my_favourite_seasons <- season_of_year[c(1,4)]
my_hated_seasons <- season_of_year[c("SUMMER","AUTUMN")]
holiday_season <- season_of_year$SUMMER… but cannot modify it:
season_of_year$SUMMER <- "something"
#> Error in `$<-.enum_type`(`*tmp*`, SUMMER, value = "something"): You cannot modify enum_type values!You can also choose a random subset:
Objects have thier own classes, which can be checked:
class(season_of_year)
#> [1] "enum_type"
class(holiday_season)
#> [1] "enum_value"
is.enum_type(season_of_year)
#> [1] TRUE
is.enum_value(holiday_season)
#> [1] TRUEYou can add methods to enum_type which will be accessing its fields. You can access these fields using their names with dot before it. Thus it’s not recommended to add fields which names begin with dot.