-
Notifications
You must be signed in to change notification settings - Fork 998
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
implement frev as fast base::rev alternative #5907
base: master
Are you sure you want to change the base?
Conversation
The goal is to export right? Should we also support |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5907 +/- ##
=======================================
Coverage 97.51% 97.51%
=======================================
Files 80 80
Lines 14979 14957 -22
=======================================
- Hits 14607 14586 -21
+ Misses 372 371 -1 ☔ View full report in Codecov by Sentry. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
* Fix 5492 by limiting the costly deparse to `nlines=1` * Implementing PR feedbacks * Added inside * Fix typo in name * Idiomatic use of inside * Separating the deparse line limit to a different PR --------- Co-authored-by: Michael Chirico <chiricom@google.com>
* Added my improvements to the intro vignette * Removed two lines I added extra as a mistake earlier * Requested changes
inst/tests/tests.Rraw
Outdated
# attributes | ||
x = structure(1:10, class = c("IDate", "Date"), att = 1L) | ||
test(2249.51, attr(frev(x, copy=TRUE), "att"), 1L) | ||
test(2249.52, attr(frev(x, copy=FALSE), "att"), 1L) |
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.
Note that this will break e.g. the gregexpr()
output, where the attributes are created to match the actual object order. Nothing we can do here besides document the potential issue, I think.
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.
True, but this problem also appears with base::rev
?
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.
OK, let's just document that we copy base::rev behavior for attributes?
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.
Hmm but rev()
drops attributes?
names(attributes(rev(structure(1:10, class = c("IDate", "Date"), att = 1L))))
# [1] "class"
names(attributes(rev(regexpr("[a-m]", letters))))
# NULL
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.
Good spot, I just checked with names
and class
but apparently those are special attributes.
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 added details in the docs about attributes being retained.
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 think we should rather match base::rev()
behavior and strip (non-"special") attributes. As mentioned this can have subtly broken implications -- user wanting to keep attributes around should be responsible for how to do so.
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.
Not sure I'm on the same side here. Retaining attributes with all operations on a data.table is an often mentioned feature, users would like.
I know that it's not user-facing now, but what would be the behavior for setrev
for stripping attributes? Strip them as a side effect or keep them?
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.
We drop attributes now on frev
. For setrev
we still keep them but can change if wanted.
For the special case of zero length vectors, attributes are still copied (rev
behaves here the same).
AFAIR I copied the argument name from
So what about
That's exactly the reason |
Possibly, but it's easy to think "faster --> unequivocally better" and use it somewhat carelessly / forgetting the full implications of the choice. And that's just on the part of the code author. We also need to consider code reviewers and future readers/maintainers. It's with that (and more) in mind that we really want to limit the API surface of in-place operations of data.table IMO. Anxiety about getting bitten by mutability issues is quite a common reason to avoid touching {data.table}; this problem gets worse if readers/writers of code using {data.table} need to be wary of reference semantics in "new"/"unexpected" places. By sticking to a simple rule: "By-reference updates can only happen when you see I missed
Good catch, I'd forgotten about Lines 5 to 6 in 54f9048
|
Let's add setdroplevels then. We could have dot prefixed non exported function that had copy art and then exported ones that goes via this .droplevels |
Totally agree, @MichaelChirico. Having a clear set of expectations for mutability is going to make adoption for new users much easier. |
I think calling by reference operation on a vector alone is more likely to cause troubles, that possibly could be mentioned with some example, like changing R constant value |
Note that in the current PR, there's no user-facing way to call |
Generated via commit cabddd2 Download link for the artifact containing the test results: ↓ atime-results.zip Time taken to finish the standard R installation steps: 12 minutes and 12 seconds Time taken to run |
Closes #5885