Skip to contents

Make an Active Binding

Usage

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

set.seed(1234)
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.1137034
x
#> Evaluating function of active binding
#> [1] 0.6222994
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.6092747
rm(x) # cleanup