Make an Active Binding

sym %<-active% value

Arguments

sym

symbol to bind

value

A function to call when the value of sym is accessed.

Value

value, invisibly

Details

Active bindings defined in a %py_class% are converted to @property decorated methods.

See also

Examples

x %<-active% function(value) { message("Evaluating function of active binding") if(missing(value)) runif(1) else message("Received: ", value) } x
#> Evaluating function of active binding
#> [1] 0.08075014
x
#> Evaluating function of active binding
#> [1] 0.834333
x <- "foo"
#> Evaluating function of active binding
#> Received: foo
x <- "foo"
#> Evaluating function of active binding
#> Received: foo
x
#> Evaluating function of active binding
#> [1] 0.6007609
rm(x) # cleanup