Closed krlmlr closed 4 years ago
This doesn't seem to work for subclasses that inherit their initialize
method. Could you make it work for those as well?
A <- R6Class("A", public = list(initialize = function(a = "", ..., b) NULL))
B <- R6Class("B", inherit = A)
B$new( <Tab>
It feels a little weird to me to inline the whole new_dots
function into the new
function. Could the new
function call out to a separate new_dots
function instead?
Lazy evaluation of the inherit
argument makes inheriting constructors super-difficult. I'll have to create an active binding for new()
. Please confirm that you're willing to review/support such a solution.
Oh, it makes sense that the dynamic inheritance would pose a problem for inheriting constructors. I don't think that having an active binding is worthwhile here.
Thanks. Why is inherit
evaluated lazily anyway? Is it because otherwise you can't inherit a class that is defined after your class (in collation order)?
It's because of #12.
Now the argument list is available only if there's an explicit initializer, otherwise we still use ... . All tests still pass locally.
I think this fixes #104. #47 is a slightly different issue.
Closing this in favor of #191, which is based on the work in this PR.
Fixes #47: The original boilerplate for new() is available as new_dots().
If a class has an initialize() method,new() is created as a function with proper argument list, which forwards to a local copy of new_dots().All tests pass without modification.
Compared to #63, this also works when the new() method is assigned to a variable, a use case I've encountered recently.