r-lib / R6

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

Revert new() argument injection #194

Closed wch closed 4 years ago

wch commented 4 years ago

Closes #193. This reverts the changes from #191.

For future reference, if we ever are to implement this feature, it will need to pass the tests that were removed in this PR, and it will also have to handle the issue with non-standard evaluation mentioned in #191.

gaborcsardi commented 4 years ago

FWIW, a different approach might work here. How about creating a new() function that is made up of the current new() function, and the body of the initialize() function? This would happen when the class is created, I guess. We would basically modify the initialize() function, by injecting some initialization code into its body.

I think this is a good approach, because there is a single function call to new(), and there are no issues with NSE, etc.

wch commented 4 years ago

I'm not so sure that could work. The new function is part of the class generator, but initialize is part of the instantiated object. new creates the environments (like self, private, and super) and populates them with members, then it invokes initialize.

new needs to have access to objects from the class generator (like the lists of public and private members, the superclass generator, whether objects of the class are cloneable, etc), while initialize needs to have access to the self, private, and super objects, after they've been populated.

I don't see a way to make this work, but if someone is able to do it, I'd be happy to look at a PR.

wch commented 4 years ago

FWIW, I just learned that the RStudio IDE has had autocomplete support for $new() for some time now. https://github.com/rstudio/rstudio/blob/2a9eaa49/src/cpp/session/modules/SessionRCompletions.R#L654-L658