Skip to content

unnest_wider() drops column if it contains empty lists #1125

@RoelVerbelen

Description

@RoelVerbelen

Inconsistency in output format that came up when processing nested lists that might be empty:

library(tidyr)
df <- tibble(
  x = list(list(z = list(1)), list(z = list(2))), 
  y = 1:2
  )
# column z as expected
df %>% unnest_wider(x)
#> # A tibble: 2 x 2
#>   z              y
#>   <list>     <int>
#> 1 <list [1]>     1
#> 2 <list [1]>     2


df <- tibble(
  x = list(list(z = list()), list(z = list())), 
  y = 1:2
)
# column z not present
df %>% unnest_wider(x)
#> # A tibble: 2 x 1
#>       y
#>   <int>
#> 1     1
#> 2     2

Created on 2021-06-10 by the reprex package (v1.0.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorrectangling 🗄️converting deeply nested lists into tidy data frames

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions