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

Comments

@frederikziebell
Copy link

@frederikziebell frederikziebell commented Aug 1, 2018

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 krlmlr commented Sep 13, 2018

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

@hadley

This comment has been hidden.

@frederikziebell

This comment was marked as off-topic.

@hadley

This comment has been hidden.

@khailper
Copy link
Contributor

@khailper khailper commented Jan 19, 2019

I'll try this.

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

@hadley 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 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants