-
Notifications
You must be signed in to change notification settings - Fork 1k
new helper function fctr to retain order of input in levels, closes #… #4843
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4843 +/- ##
=======================================
Coverage 98.69% 98.70%
=======================================
Files 79 79
Lines 14688 14695 +7
=======================================
+ Hits 14497 14504 +7
Misses 191 191 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
In fabafed I added extra argument, |
|
Needs unit test for #5327 so it can close that one as well |
MichaelChirico
left a comment
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.
Searching around on cran, I do see calls like factor(x, levels=unique(x)) pretty commonly:
https://github.com/search?q=org%3Acran%20%2Ffactor%5C(.*unique%5C(%2F&type=code
As well as more generally in lang:R:
https://github.com/search?q=lang%3AR+%2Ffactor%5C%28.*unique%5C%28%2F&type=code
I think that justifies a new function even though it's just a base wrapper.
We also see ample rev=TRUE cases.
I only quibble about the name, there's a tension between "its good to have something concise" and "readers should be able to infer something about it from its name".
Maybe u_factor / factor_u (unsorted factor() / unique factor())? uns_factor / unq_factor?
Alternatively, maybe this is something to propose to r-devel first?
I doubt they would consider adding that |
we can guess it's related to factors, but not anything else. is it fast alternative (as is most common for our helpers)? is it a related-but-similar S3 class?
not as a separate function, surely, but possibly as new argument(s) to factor() |
not really, therefore no f prefix :)
|
really? is.object(factor())
# [1] TRUE
methods(class = 'factor')
# [1] all.equal as.character as.data.frame as.Date as.list as.logical as.POSIXlt as.vector c coerce droplevels [<-
# [13] [ [[<- [[ format initialize is.na<- length<- levels<- Math Ops plot print
# [25] relevel relist rep show slotsFromS3 summary Summary xtfrm
# see '?methods' for accessing help and source code |
|
I would like more feedback from other @Rdatatable/committers here on whether (1) we want to export a simple {base} wrapper (2) the proposed naming The closest I can see in terms of "nearness" to base R functionality would be |
|
Just my opinion: 1) it would have nearly no need for maintenance going forward so if it is useful for Jan and others, seems like a low lift to add. 2) I'm fine with the name. |
|
Jan WDYT about extending this to support the "normal" factor() default of sorted levels? that way users can have a one-stop shop instead of needing to switch between the proposed fctr() and factor() |
uh sorry, I meant |
|
by
you mean
? If so then I would add another arg |
yes that's what I had in mind. basically fctr() becomes extended factor() with a different default. |
|
No obvious timing issues in HEAD=fctr Generated via commit bbba929 Download link for the artifact containing the test results: ↓ atime-results.zip
|
MichaelChirico
left a comment
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.
Looking great now, thanks!
PTAL at the updated NEWS/Rd descriptions & merge if you're happy :)


closes #4837