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.

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.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