Skip to content
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

Merged
merged 9 commits into from
Nov 14, 2024
Merged

Vignette typos fixes #492

merged 9 commits into from
Nov 14, 2024

Conversation

mattheaphy
Copy link
Contributor

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 a setter for the Range class, the setter 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 of Range(start = 1, end = 10) was this:

<Range>
 @ start : num 1
 @ end   : num(0) # should be 10
 @ length: num(0) # should be 9

I updated the length setter to short circuit and return the original object when value 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 the rle() function, and this was creating incorrect output for rle(1:10).

Run Length Encoding
  lengths: int [1:10] 1 2 3 4 5 6 7 8 9 10 # should be all 1's
  values : logi(0) # should be 1-10

I used the name new_rle here instead that seemed to clean things up.

@@ -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)
Copy link
Member

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?

Copy link
Member

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(
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

@mattheaphy mattheaphy Nov 13, 2024

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.

Copy link
Member

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.

Copy link
Member

@t-kalinowski t-kalinowski left a 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!

@hadley hadley merged commit 534f5b7 into RConsortium:main Nov 14, 2024
@hadley
Copy link
Member

hadley commented Nov 14, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants