Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Unnesting tibble with zero rows removes unnested column #483
Here is an example that produces the problem:
If the special case occurs that the tibble being unnested has no rows, all code acting on the unnested column breaks.
I see an error (possible due to dev dplyr)
library(tidyr) df <- tibble::tibble( a = list(c(1, 2), 3), b = c(4,5) ) df %>% unnest(a) %>% names() #>  "b" "a" df %>% filter(b==1) %>% unnest(a) %>% names() #> Error in data.matrix(data): (list) object cannot be coerced to type 'double'
Created on 2019-01-04 by the reprex package (v0.2.1.9000)
I get the same error. Here is my
referenced this issue
Jan 4, 2019
added a commit
Jan 19, 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)