-
Notifications
You must be signed in to change notification settings - Fork 35
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
roworder() does not sort columns of Interval class from lubridate #418
Comments
Thanks, yeah I'll think about your suggestion of issuing a warning, but in general, I don't think it is a great idea to check for the existence of lots of different non-base-R classes at the C-level that may give different bevahior. |
Full disclaimer, I'm not a That being said, I've encountered similar issues and just wrote a custom
From there you can probably write your own function to do something similar for data frames. |
Thanks so much for the thorough response, @SebKrantz. The explanation makes a lot of sense, and I understand the decision to stick with programming for the more common classes (and hesitancy regarding class-specific warnings). Just noticed a typo near the suggestion in my initial post--should've said "in the former case" (not the latter), but I think that was understood! If nothing else, I'm hoping this post helps make the incompatibility a bit more visible. The issue can be easy to miss when working with wider data frames. If there's other pieces in the documentation that indicate the incompatibility, it wasn't as obvious to me, at least as someone newer to these more advanced/custom elements of objects in R. Thank you as well, @NicChr, for sharing the code! |
It appears that roworder() does not sort columns of class Interval from lubridate. If roworder() is applied to a data frame that contains an Interval class column, all non-Interval columns will be sorted as specified, but the Interval class columns will remain in the order as in the originating data frame.
The same issue occurs with data.table's setorder(). A workaround is to use dplyr's arrange(), which correctly sorts all columns, regardless of class. Of course, arrange() can be much slower depending on the size of your data frame.
Another alternative is to convert the Interval class column(s) to character before using roworder(), but if the Interval class is needed for later operations, this might not be ideal.
Similar to another issue pertaining to lubridate Intervals (see #186), this may be more of a limitation than a bug. In the latter case, including a note in the documentation might be helpful and/or a warning if an Interval class column is detected in the data frame being sorted.
Created on 2023-05-03 with reprex v2.0.2
The text was updated successfully, but these errors were encountered: