Skip to contents

Fills the absent fields of type option() that a struct declares with a fill policy: a field of field(option(T), context = TRUE) from context, and a field of field(option(T), compute = calc(expr)) from its expression over the other fields, in dependency order. The result is a new value, validated; x is unchanged. A context field missing from context stays absent.

Usage

r8resolve(x, context = list())

Arguments

x

An R8 struct value.

context

Named list: Values of context fields, by name.

Value

The resolved R8 value.

Examples

op <- options(r8.namespace = "demo")
Dose <- new_struct("Dose", fields = list(
  mg = field(option(type_double()), context = TRUE, unit = "mg"),
  g = field(option(type_double()), compute = calc(mg / 1000), unit = "g")
))
r8resolve(Dose(), context = list(mg = 250))$g
#> [1] 0.25
options(op)