Enum_Assertion: Enum assertion type checking

Description Usage Arguments Value Examples

Description

Assertion for controlling object, argument, and return types. Allows for the type checking of enums and enum members.

This function requires the typed package to operate. See typed::?() for more details.

Usage

1

Arguments

...

a value to check type assertions with

Value

any

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# If you leverage the {typed} package, you can make use
# of the `Enum()` assertion for type checking:

library(typed, quietly = TRUE, warn.conflicts = FALSE)

# Variable 'x' must correspond to an enum
Enum() ? x <- enum(a, b, c)

# Variable 'x' must correspond to a variable in an enum
Enum(enum(a, b, c)) ? x <- 2

# Argument 'x' must correspond to a variable in an enum
my_function <- ? function(x = ? Enum(enum(a, b, c))) {
    print("success!")
}

# Function must return an enum
func_return <- Enum() ? function() {
    return(
        enum(a, b, c)
    )
}

ElianHugh/enumr documentation built on Dec. 17, 2021, 6:25 p.m.