R: Use active binding in object generator to conditionally add new class to R6 objects
问题 I have a simple R6 object generator: thing <- R6Class("youngThing", private = list( ..age = 0), active = list( age = function(){ private$..age <- private$..age + 1 private$..age } ) ) That gives me a simple R6 object, where ..age increases by 1 every time the active age field is called: a_thing <- thing$new() a_thing$age # [1] 1 I want the object class of a_thing to change given a threshold value of the private field ..age , like this: class(a_thing) # [1] "youngThing" "R6" for(timestep in 1