Tweak R6 usage#1815
Merged
Merged
Conversation
* Use `obj$method()` not `{classname}$method()`
* Use `{classname}()` not `{classname}$new()`
* `rd_r6_method()` no longer needs alias
Fixes #1026
gaborcsardi
approved these changes
Mar 17, 2026
| if (method == "initialize") { | ||
| class | ||
| } else { | ||
| paste0("obj$", method) |
Member
There was a problem hiding this comment.
I know <class>$method is not technically correct, but it is more informative than the constant obj$ prefix.
Member
Author
There was a problem hiding this comment.
Because then it's confusing that Foo$new() literally means to call Foo$new(), but Foo$something_else() does not.
Member
There was a problem hiding this comment.
Good point. Is Foo_object$method() too long? How about adding a call that actually creates an object? Something like this?
Foo_object <- Foo$new(...)
Foo_object$method1()
...
Member
Author
There was a problem hiding this comment.
Those both feel a bit long to me.
Member
Author
There was a problem hiding this comment.
We could just do $method()? Or is that too confusing?
Member
There was a problem hiding this comment.
$method is not valid R code.
Member
There was a problem hiding this comment.
How about
o <- Foo$new(...)
o$method1()
...
?
Member
Author
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Consistently refer to methods in the same way in every location.
Fixes #1258