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

desc() checks the number of arguments. #285

Merged
merged 5 commits into from
Sep 7, 2021

Conversation

eutwt
Copy link
Collaborator

@eutwt eutwt commented Aug 22, 2021

Currently if you pass two arguments to desc as in desc(a, b), it is converted to a - b by dt_squash_call. This PR adds a check to error if more than one argument is provided.

A similar issue was fixed in dplyr: tidyverse/dplyr#5929

Before this PR:

library(dplyr, warn.conflicts = FALSE)
library(dtplyr, warn.conflicts = FALSE)

dt <- lazy_dt(data.frame(a = rep(1:2, each = 2), b = 1:4))

dt %>% 
  arrange(desc(a, b))
#> Source: local data table [4 x 2]
#> Call:   `_DT1`[order(a - b)]
#> 
#>       a     b
#>   <int> <int>
#> 1     2     4
#> 2     1     2
#> 3     2     3
#> 4     1     1
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results

Created on 2021-08-22 by the reprex package (v2.0.1)

After this PR:

library(dplyr, warn.conflicts = FALSE)
library(dtplyr, warn.conflicts = FALSE)

dt <- lazy_dt(data.frame(a = rep(1:2, each = 2), b = 1:4))

dt %>% 
  arrange(desc(a, b))
#> Error: `desc()` expects exactly one argument.

Created on 2021-08-22 by the reprex package (v2.0.1)

@hadley
Copy link
Member

hadley commented Sep 7, 2021

Looks good — can you please add a bullet to the top of NEWS.md? It should briefly describe the change and end with (@yourname, #issuenumber).

@eutwt
Copy link
Collaborator Author

eutwt commented Sep 7, 2021

This is fixing a bug in a feature which has not yet been in any release, and the feature itself already has a bullet. Should I still add a new one?

@eutwt
Copy link
Collaborator Author

eutwt commented Sep 7, 2021

I went ahead and added one, but can also revert the commit, either way. Not sure what the convention is.

@hadley
Copy link
Member

hadley commented Sep 7, 2021

Oh, support for desc() is new in this release? In that case, no bullet is necessary. Sorry!

This reverts commit 3cf592b.
@eutwt
Copy link
Collaborator Author

eutwt commented Sep 7, 2021

Yep, new this release. Reverted the news commit

@hadley hadley merged commit 53d032b into tidyverse:master Sep 7, 2021
@hadley
Copy link
Member

hadley commented Sep 7, 2021

Thanks!

@eutwt eutwt deleted the check_desc_nargs branch September 7, 2021 17: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