-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: Support descending sort for character and other non-numeric data #175
Conversation
Thanks. We need to adopt the translation of |
Thanks, good catch. I think we can just special-case |
I pushed a new version that handles calls to The arguments ("dots") is iterated twice which is not ideal, but I found it to be cleaner than manipulating dots-argument in place. |
Do you have comments on the above @krlmlr ? If this was already on your todo-list, sorry for the unnecessary ping. |
Thanks for the ping. I was waiting for duckdb 1.0.0 to hit CRAN, which now happened. We'll need |
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, this looks workable, just a few remarks on style.
R/arrange.R
Outdated
ascending <- sapply(dots,function(dot) { | ||
expr <- get_expr(dot) | ||
if (typeof(expr) != "language") return(TRUE) | ||
return(expr[[1]] != "desc") | ||
}) |
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.
map_lgl()
is.call()
perhaps?- Avoid
return()
as last statement - Extract this and the next map into a function that returns a data frame (or a list with two parallel vectors) and uses ... a
for
loop?
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! I refactored the extraction of sort order and manipulation of dots into a separate function.
Also the parameter ascending
in rel_order()
now has NULL as a default argument (the tests for previous commit failed due to not having a default argument)
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, let me play with it and finish it.
R/arrange.R
Outdated
if (length(expr) > 2) cli::cli_abort("desc() must be called with exactly one argument.") | ||
|
||
ascending[i] <- FALSE | ||
dots[[i]] <- new_quosure(expr[[2]]) |
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.
Do we need to use the original environment here?
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! Good point.
Thanks! |
Closes #92.
Creating a
desc
macro feels a bit like a work-around as it is created for the sole purpose of not raising a function-not-found -error. Couldn't think of an easy alternative. What do you think @krlmlr ?