[<-.enum | R Documentation |
Access an enumeration by name or value.
## 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]
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'. |
'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'.
`[`(enum) <- value
: Forbids enum value assignments
`[[`(enum) <- value
: Forbids enum value assignments
names(enum) <- value
: Forbids enum value assignments
[
: Extract elements of an enum
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.
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.