extract-enum: Extract Enum Value

[<-.enumR Documentation

Extract Enum Value

Description

Access an enumeration by name or value.

Usage

## S3 replacement method for class 'enum'
x[...] <- value

## S3 replacement method for class 'enum'
x[[...]] <- value

## S3 replacement method for class 'enum'
names(x) <- value

## S3 method for class 'enum'
x[[..., exact = TRUE]]

## S3 method for class 'enum'
x[..., drop = FALSE]

Arguments

x

enum object from which to extract element(s)

...

a specification of indices.

value

an 'R' object

exact

Controls possible partial matching of '[[' when extracting by a character vector. The default is no partial matching. Value 'FALSE' allows partial matching without any warning.

drop

With 'drop=TRUE' the result will be integer. By default subsetting returns an 'enum'.

Value

'x[[...]]' returns the value as 'enum'.

For 'x[...]' the default return type is 'enum'. Duplicate values or 'drop=TRUE' will drop the return type to 'integer'.

Functions

  • `[`(enum) <- value: Forbids enum value assignments

  • `[[`(enum) <- value: Forbids enum value assignments

  • names(enum) <- value: Forbids enum value assignments

  • [: Extract elements of an enum

Note

Unlike equivalent functions enumerations are not subset by index. Every enumeration value can be accessed by string or the according integer value. Subsetting *by position* is not possible for enumerations.

Unlike the equivalent function in base R this function does not throw a warning when 'exact' is 'NA'.

'x[[...]]' does not accept vector arguments.

Examples

e <- enum(a = 1, x = 2, c = 4)
e[[2]]
#> x
#> 2
e[["x"]]
#> x
#> 2
tryCatch(e[[3]], error = function(e) e ) # does not exist
#> Attempt to access non-existing enum value

SigurdJanson/plainEnum documentation built on Aug. 27, 2022, 1:40 a.m.