Closed DavisVaughan closed 1 year ago
I just noticed this absence while writing for R4DS, so I definitely think we should add keep_empty
support.
It's worth noting the behaviour is different with NULL
:
library(tidyr)
df <- tibble(
x1 = list("a", character()),
x2 = list("a", NULL)
)
df |> unnest_longer(x1)
#> # A tibble: 1 × 2
#> x1 x2
#> <chr> <list>
#> 1 a <chr [1]>
df |> unnest_longer(x2)
#> # A tibble: 2 × 2
#> x1 x2
#> <list> <chr>
#> 1 <chr [1]> a
#> 2 <chr [0]> <NA>
Created on 2022-08-10 by the reprex package (v2.0.1)
This is somewhat related to the strict
argument to unnest_wider()
, because the motivation for handling NULL
in this way comes from JSON.
From https://community.rstudio.com/t/unnest-longer-drops-lists-rows-with-character-0/132748
Original example:
Created on 2022-03-28 by the reprex package (v2.0.1)
Minimal reprex:
Created on 2022-03-28 by the reprex package (v2.0.1)
It may be as simple as passing
keep_empty
through to theunchop()
call inunnest_longer()
, but I'd need to think about it critically to make sure