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

Translate desc(col) to -col inside arrange() #227

Merged
merged 2 commits into from
Mar 21, 2021

Conversation

markfairbanks
Copy link
Collaborator

No description provided.

@hadley
Copy link
Member

hadley commented Mar 20, 2021

And that works for character vectors?

@markfairbanks
Copy link
Collaborator Author

Yep. It's their recommended way so that you can sort character vectors descending using their radix sorting.

library(data.table)
library(dplyr)

dt <- data.table(x = sample(letters, 100000, TRUE))

bench::mark(
  minus = dt[order(-x)],
  desc = dt[order(desc(x))],
)
#> # A tibble: 2 x 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 minus        1.16ms   1.71ms    543.      2.85MB     13.3
#> 2 desc       437.11ms 450.29ms      2.22    8.06MB      0

@hadley hadley merged commit f8ef87a into tidyverse:master Mar 21, 2021
@hadley
Copy link
Member

hadley commented Mar 21, 2021

Good to know, thanks!

@markfairbanks markfairbanks deleted the desc-as-minus branch March 28, 2021 13:56
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.

2 participants