An analogue to S7::new_union(). Defines a new property from multiple.
Arguments
- ...
S7 classes or properties to union.
- default
Any. Passed to
S7::new_property().- e1, e2
S7 classes or properties to union.
Details
property_union() uses the first member default that satisfies the union.
Pass default = NULL for a NULL default.
Examples
library(S7)
Piece := new_class(
properties = list(
id = property_union(S7::class_character, S7::class_integer)
)
)
Piece("a")
#> <Piece>
#> @ id: chr "a"
Piece(1L)
#> <Piece>
#> @ id: int 1
library(S7)
Piece := new_class(
properties = list(id = class_string | property_range_discrete(1L, 6L))
)
Piece(3L)
#> <Piece>
#> @ id: int 3