Returns x when it is a value of type, and its upcast when type is an
ancestor of its type (r8upcast()). Otherwise calls the From(source)
impl of type for the nearest source with one: for an R8 value, its type,
then its ancestors through extends, nearest first; for any other object,
its class vector as .class2() gives it, which includes the implicit
classes, such as "matrix", "integer", and "numeric", and an S4
object's superclasses. The impl receives x
unchanged, and its result must be a value of type. Conversions are not
chained.
Value
A value of type. A source without an impl raises
r8_dispatch_error, and an impl's result of another type
r8_result_error.
Examples
op <- options(r8.namespace = "demo")
Pct <- new_struct("Pct", fields = list(p = type_double(min = 0, max = 100)))
impl(From("numeric"), Pct, methods = list(from = function(x) Pct(p = x * 100)))
r8convert(0.25, Pct)$p#> [1] 25options(op)