r-lib / R6

Encapsulated object-oriented programming for R
https://R6.r-lib.org
Other
405 stars 56 forks source link

Inherit from an instance #136

Closed jakob-r closed 4 years ago

jakob-r commented 6 years ago

What are your thoughts on the possibility to not inherit only from an R6ClassGenerator but also form an R6 instance?

library(R6)

Thing = R6Class(
  classname = "Thing", 
  public = list(
    name = NULL,
    initialize = function(name) self$name = name
  )
)

thing1 = Thing$new("thing1")

Thing1_1 = R6Class(
  classname = "Thing1_1",
  inherit = thing1,
  public = list(
    colour = NULL,
    initialize = function(colour) self$colour = colour
  )
)
wch commented 6 years ago

I don't think that would be feasible without major changes. What is the use case you have in mind?