Skip to contents

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@name

Arguments

x

An R8 value.

name

The name.

i

Character: The field name; for x[i], one name or more, each once in an assignment.

...

Not used.

value

The new field value; for x[i], a list of new field values.

object

An R8 value.

Value

The field's value, a named list of fields, or the new R8 value.

Does not return.

Details

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] 0
x[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
x[c("lo", "hi")] <- list(5, 9)
x
#> <demo::Interval>
#>   lo: 5
#>   hi: 9
options(op)