Skip to content

Operation on empty rowwise list column causes "subscript out of bounds" error #5804

Description

@mlell

If I perform an operation on an empty rowwise data frame, I would expect the result to be an empty data frame as well. Its similar to a for loop being skipped when the vector of indices is empty.

If I do this on a rowwise tibble with zero rows, it behaves as expected:

tibble(a = character(0)) %>%
  rowwise() %>%
  mutate(n = nchar(a)) %>%
  {stopifnot(all.equal(., 
    rowwise(tibble(a = character(0), n = integer(0))))}

This does not work for list columns

tibble(a = list()) %>%
  rowwise() %>% 
  mutate(n = lengths(a))
Error: Problem with `mutate()` input `n`.
x subscript out of bounds
ℹ Input `n` is `lengths(a)`.

I would instead expect a return value like

rowwise(tibble(a = list(), n = integer()))

I tested this issue with dplyr, commit d56404c

Activity

  1. added
    bugan unexpected problem or unintended behavior
    on Mar 9, 2021
  2. added this to the 1.0.6 milestone on Mar 9, 2021
  3. added a commit that references this issue on Mar 9, 2021
    f41d34e
  4. added a commit that references this issue on Mar 9, 2021
    e60e32e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugan unexpected problem or unintended behavior

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions