You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently it keeps NULL elements, but drops empty vectors like integer().
It should work like unchop(keep_empty = FALSE) which drops both NULL and integer().
This is heavily related to #1339. I imagine that to be able to add keep_empty to unnest_longer() we will have to resolve this. I think it requires changes to tidyr:::elt_to_long()'s handling of NULL. When keep_empty = FALSE (the default) it should probably use unspecified(0L) and an empty vector for the index if needed. The current behavior looks to be what should happen for keep_empty = TRUE.
Fixing this is probably a small breaking change. But I think it is definitely worth it for package consistency.
library(tidyr)
df<- tibble(
x=list(NULL, 1L, integer())
)
df#> # A tibble: 3 × 1#> x #> <list> #> 1 <NULL> #> 2 <int [1]>#> 3 <int [0]># Inconsistent:# Keeps the `NULL` as `NA`.# Drops the `integer()`.
unnest_longer(df, x)
#> # A tibble: 2 × 1#> x#> <int>#> 1 NA#> 2 1# Consistent with our definition of "empty".# - Drops `NULL`# - Drops `integer()` (size 0 vectors)
unchop(df, x)
#> # A tibble: 1 × 1#> x#> <int>#> 1 1# - Keeps `NULL` as NA# - Keeps `integer()` as NA
unchop(df, x, keep_empty=TRUE)
#> # A tibble: 3 × 1#> x#> <int>#> 1 NA#> 2 1#> 3 NA
Currently it keeps
NULL
elements, but drops empty vectors likeinteger()
.It should work like
unchop(keep_empty = FALSE)
which drops bothNULL
andinteger()
.This is heavily related to #1339. I imagine that to be able to add
keep_empty
tounnest_longer()
we will have to resolve this. I think it requires changes totidyr:::elt_to_long()
's handling ofNULL
. Whenkeep_empty = FALSE
(the default) it should probably useunspecified(0L)
and an empty vector for theindex
if needed. The current behavior looks to be what should happen forkeep_empty = TRUE
.Fixing this is probably a small breaking change. But I think it is definitely worth it for package consistency.
Created on 2022-06-02 by the reprex package (v2.0.1)
The text was updated successfully, but these errors were encountered: