x$name and x[["name"]] read a field by its exact name, and
x[c("a", "b")] several, as a plain named list; an unknown name is an
error. as.list(x) gives every field as a plain named list, in declaration
order and with NULL for an absent field, so that lapply(), vapply(),
and Filter() take a value.
@ reads the associated items of a type, not the fields of a value.
Usage
# S3 method for class 'r8_value'
x$name
# S3 method for class 'r8_value'
x[[i, ...]]
# S3 method for class 'r8_value'
x[i, ...]
# S3 method for class 'r8_value'
as.list(x, ...)
# S3 method for class 'r8_value'
x$name <- value
# S3 method for class 'r8_value'
x[[i]] <- value
# S3 method for class 'r8_value'
x[i] <- value
# S3 method for class 'r8_value'
object@nameDetails
x$name <- v and x[["name"]] <- v return a new value, validated; x is
unchanged. x[c("a", "b")] <- list(v, w) replaces several fields: each is
validated, then the rules that read any of them run once, on the new value,
so a rule between the fields holds for the result and not for each step.
The list has one element per name, and its own names, when it has them, are
the fields'.
Examples
op <- options(r8.namespace = "demo")
Interval <- new_struct(
"Interval",
fields = list(lo = type_double(), hi = type_double())
)
x <- Interval(lo = 0, hi = 2)
x$lo#> [1] 0x[c("lo", "hi")]#> $lo
#> [1] 0
#>
#> $hi
#> [1] 2
#> vapply(x, class, "")#> lo hi
#> "numeric" "numeric" x$lo <- 1
x#> <demo::Interval>
#> lo: 1
#> hi: 2#> <demo::Interval>
#> lo: 5
#> hi: 9options(op)