R6
class with generic (abstract) new cloning functionality.
Public fields
object_generator
Class object generator used to create new clones, particularly for user inheritance.
attached
A list of dynamically attached attributes (name-value pairs).
Methods
Method new()
Initialization method saves an object generator for new cloning.
Usage
GenericClass$new(object_generator = NULL, ...)
Method new_clone()
Creates a new (re-initialized) object of the current (inherited) object class with optionally passed parameters.
Examples
object1 <- GenericClass$new()
class(object1)
#> [1] "GenericClass" "R6"
# Referencing
object_ref <- object1
object_ref$attached$a <- 1
object1$attached
#> $a
#> [1] 1
#>
# Cloning
object2 <- object1$clone()
object2$attached$b <- 2
object1$attached
#> $a
#> [1] 1
#>
object2$attached
#> $a
#> [1] 1
#>
#> $b
#> [1] 2
#>
# New cloning
object3 <- object1$new_clone()
object3$attached$c <- 3
object1$attached
#> $a
#> [1] 1
#>
object3$attached
#> $c
#> [1] 3
#>