Make an Active Binding
sym %<-active% value
symbol to bind
A function to call when the value of sym
is accessed.
value
, invisibly
Active bindings defined in a %py_class%
are converted to
@property
decorated methods.
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.8365774
x
#> Evaluating function of active binding
#> [1] 0.9449075
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.5089196
rm(x) # cleanup