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

Unnesting tibble with zero rows removes unnested column #483

Closed
frederikziebell opened this issue Aug 1, 2018 · 7 comments
Closed

Unnesting tibble with zero rows removes unnested column #483

frederikziebell opened this issue Aug 1, 2018 · 7 comments
Labels
bug an unexpected problem or unintended behavior rectangling 🗄️ converting deeply nested lists into tidy data frames tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day

Comments

@frederikziebell
Copy link

Here is an example that produces the problem:

df <- tibble(
 a = list(c(1, 2), 3),
 b = c(4,5)
)

df %>%
  unnest(a) %>%
  colnames
# [1] "b" "a"

df %>%
  filter(b==1) %>%
  unnest(a) %>%
  colnames
# [1] "b"

If the special case occurs that the tibble being unnested has no rows, all code acting on the unnested column breaks.

@krlmlr
Copy link
Member

krlmlr commented Sep 13, 2018

Thanks, confirmed with both the CRAN version and 581c2c0.

@hadley hadley added bug an unexpected problem or unintended behavior rectangling 🗄️ converting deeply nested lists into tidy data frames labels Jan 4, 2019
@hadley

This comment has been minimized.

@frederikziebell

This comment has been minimized.

@hadley

This comment has been minimized.

@hadley hadley added the tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day label Jan 4, 2019
@khailper
Copy link
Contributor

I'll try this.

khailper added a commit to khailper/tidyr that referenced this issue Jan 19, 2019
@hadley
Copy link
Member

hadley commented Jan 22, 2019

A bit more of a reprex to help me understand the problem:

library(tidyr)

df <- tibble::tibble(a = list(1), y = 1)
df %>% unnest(a) %>% str()
#> Classes 'tbl_df', 'tbl' and 'data.frame':    1 obs. of  2 variables:
#>  $ y: num 1
#>  $ a: num 1
df %>% .[0, ] %>% unnest(a) %>% str()
#> Classes 'tbl_df', 'tbl' and 'data.frame':    0 obs. of  1 variable:
#>  $ y: num

Created on 2019-01-22 by the reprex package (v0.2.1.9000)

@hadley
Copy link
Member

hadley commented Jan 22, 2019

I think the root cause is actually this:

list_col_type(character())
#> [1] "data.frame"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior rectangling 🗄️ converting deeply nested lists into tidy data frames tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day
Projects
None yet
Development

No branches or pull requests

4 participants