Skip to content

allow arrange() to accept NULL argument #6193

Closed

Description

@DanChaltiel

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.

Activity

  1. added
    featurea feature request or enhancement
    rows ↕️Operations on rows: filter(), slice(), arrange()
    on Apr 15, 2022
  2. hadley commented on Jul 21, 2022

    @hadley
    Member

    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)

  3. added this to the 1.1.0 milestone on Jul 21, 2022
  4. DavisVaughan commented on Jul 21, 2022

    @DavisVaughan
    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.
  5. added a commit that references this issue on Jul 26, 2022
    6b6af39
  6. added a commit that references this issue on Jul 29, 2022
    864fdc3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancementrows ↕️Operations on rows: filter(), slice(), arrange()

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions