-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vignette typos fixes #492
Vignette typos fixes #492
Conversation
vignettes/classes-objects.Rmd
Outdated
@@ -257,6 +257,7 @@ Range <- new_class("Range", | |||
class = class_double, | |||
getter = function(self) self@end - self@start, | |||
setter = function(self, value) { | |||
if (length(value) == 0) return(self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@t-kalinowski it probably makes sense for this to be an explicit is.null()
test, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. The default value passed in by the constructor will be double(0)
. If we want the default to be NULL
, we'd have to change the property class to NULL | class_double
, or implement a custom constructor.
@@ -109,7 +109,7 @@ rle(1:10) | |||
Alternatively you could convert it to the most natural representation using S7: | |||
|
|||
```{r} | |||
rle <- new_class("rle", properties = list( | |||
new_rle <- new_class("rle", properties = list( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rle2
? I think calling it new_
is a bit confusing because the while the object is constructor, it's also the class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, rle2
would be clearer than new_rle
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a few other instances north of this line where the name new_rle
is used that would have to be updated as well for the examples to work as the original author intended. I'll add that change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this! After looking more closely, I see that new_rle()
is indeed the best choice here. The intent is for rle()
to serve as a convenient constructor, and we show how to redefine the underlying new_rle()
from the “old-style” S3 approach to the S7 approach (in two different ways) while keeping the user-facing rle()
constructor unchanged.
Strictly speaking, it might make sense to replace the user-facing rle()
with an S7 rle
class that has a custom constructor, but that would increase the example’s size and complexity without adding much clarity, in my opinion. I’ve restored the previous new_rle()
approach.
Co-authored-by: Hadley Wickham <[email protected]>
…into vignette-typo-fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the edits!
Thank you! |
A few grammatical fixes, updates of old function / argument names, and example code updates in 3 vignettes.
Regarding code updates:
classes-objects.Rmd
In the example that included a
getter
and asetter
for theRange
class, thesetter
was getting called on object instantiation. This resulted in the supplied value of@end
being overridden to an empty vector because@length
's default value is empty. The resulting output ofRange(start = 1, end = 10)
was this:I updated the length
setter
to short circuit and return the original object whenvalue
is empty, and that gave me the correct output. I wanted to call this out because the maintainers might have a better solution in mind for handling instantiation matters like this.compatibility.Rmd
I noticed that the more natural representation of the
rle
class using S7 was overwriting therle()
function, and this was creating incorrect output forrle(1:10)
.I used the name
new_rle
here instead that seemed to clean things up.