Skip to content

Adding dplyr::select.list() to override utils::select.list() #4279

Closed

Description

@ColinFay

Following the Twitter conversation from here.

As utils::select.list() is registered as an S3, calling dplyr::select() on a list calls select.list() without informing the user, who is faced with an interactive prompt asking them to do a selection. As far as I have understood this behavior is not intended.

I think this misuse can arise if you intend to write map_df() %>% select() and you end up writing map() %>% select().

Here's a suggested solution:

  • having a message to the user that they are redirected to utils::select.list()
#' @export
select.list <- function(.data, ...) {
  message("Calling `select()` on a list, redirecting to `utils::select.list()`")
  utils::select.list(choices = .data)
}
> list(a = 12) %>% dplyr::select()
Calling `select()` on a list, redirecting to `utils::select.list()`

1: 12

Selection: 1
$a
[1] 12

> list(a = 12) %>% utils::select.list()

1: 12

Selection: 1
$a
[1] 12

Note: related to #2817

Activity

  1. romainfrancois commented on Mar 13, 2019

    @romainfrancois
    Member

    🤔 I'd rather have it abort. select.list() is not a method in the first place, signatures don't match, ...

    if the user wants to call select.list() they they should call select.list() not select().

  2. ColinFay commented on Mar 13, 2019

    @ColinFay
    Author

    That was also my first idea, but

    select.list <- function(.data, ...) {
      abort("`select()` doesn't handle lists.")
    }

    makes select.list() fail 😕

    > list(a = 12) %>% dplyr::select()
    Error: `dplyr::select()` doesn't handle lists.
    Call `rlang::last_error()` to see a backtrace
    
    > list(a = 12) %>% select.list()
    Error: `dplyr::select()` doesn't handle lists.
    Call `rlang::last_error()` to see a backtrace
    
    > list(a = 12) %>% utils::select.list()
    
    1: 12
    
    Selection: 1
    $a
    [1] 12

    (But maybe there's a workaround?)

  3. added this to the 0.8.2 milestone on May 27, 2019
  4. added 2 commits that reference this issue on May 27, 2019
    4c9eade
    0a83842
  5. lock commented on Mar 21, 2020

    @lock

    This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

  6. locked and limited conversation to collaborators on Mar 21, 2020
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions