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

allow arrange() to accept NULL argument #6193

Closed
DanChaltiel opened this issue Feb 24, 2022 · 2 comments · Fixed by #6372
Closed

allow arrange() to accept NULL argument #6193

DanChaltiel opened this issue Feb 24, 2022 · 2 comments · Fixed by #6372
Labels
feature a feature request or enhancement rows ↕️ Operations on rows: filter(), slice(), arrange()
Milestone

Comments

@DanChaltiel
Copy link
Contributor

When programming with dplyr, it can be handy to pass NULL as a value.

For instance when using group_by(), I can pass NULL when I want to use my custom function but I don't want to group on any variable.

However, while group_by() allow this syntax, arrange() throws an unexpected error:

dplyr::group_by(iris, NULL)[1,]
#> # A tibble: 1 x 5
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#>          <dbl>       <dbl>        <dbl>       <dbl> <fct>  
#> 1          5.1         3.5          1.4         0.2 setosa
dplyr::arrange(iris, NULL)[1,]
#> Error in mapply(.f, .x, .y, MoreArgs = list(...), SIMPLIFY = FALSE): zero-length inputs cannot be mixed with those of non-zero length

Created on 2022-02-24 by the reprex package (v2.0.1)

This might be related to #6093.

@hadley hadley added feature a feature request or enhancement rows ↕️ Operations on rows: filter(), slice(), arrange() labels Apr 15, 2022
@hadley
Copy link
Member

hadley commented Jul 21, 2022

Looks like this has been fixed:

df <- dplyr::arrange(mtcars, NULL)

Created on 2022-07-21 by the reprex package (v2.0.1)

But there's a new bug if you mix NULL with other variables:

df <- dplyr::arrange(mtcars, NULL, am)
#> Error: `direction` should have length 1 or length equal to the number of columns of `x` when `x` is a data frame.

Created on 2022-07-21 by the reprex package (v2.0.1)

@hadley hadley added this to the 1.1.0 milestone Jul 21, 2022
@DavisVaughan
Copy link
Member

A correct solution should handle both of these cases:

df <- dplyr::arrange(mtcars, NULL, am)
#> Error: `direction` should have length 1 or length equal to the number of columns of `x` when `x` is a data frame.

x <- NULL
df <- dplyr::arrange(mtcars, x, am)
#> Error: `direction` should have length 1 or length equal to the number of columns of `x` when `x` is a data frame.

hadley added a commit that referenced this issue Jul 26, 2022
hadley added a commit that referenced this issue Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement rows ↕️ Operations on rows: filter(), slice(), arrange()
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants