The older version of tidyr::unnest(), now called tidyr::unnest_legacy(), handles unnesting of different columns types by merging the column types.
The new version of tidyr::unnest() returns an error if some of the columns are of the same name, but different types.
I'm guessing the new version is safer, but I never had any issues with the old version.
How should I unnest a list of dataframes with different column types going forward?
For now, I can use unnest_legacy(), but if I want to use the new unnest() should I then first run something like mutate() and map() to get identical column types or is there an easier way around this issue?
Reproducible example:
library(tidyr)
a <- tibble(
value = rnorm(2),
char_vec = c(NA, "A")) # character vector
b <- tibble(
value = rnorm(2),
char_vec = c(NA, NA)) # logical
df <- tibble(
file = list(a, b))
# New tidyr::unnest()
unnest(df, cols = c(file))
#> No common type for `..1$file$char_vec` <character> and `..2$file$char_vec`
#> <logical>.
# Old tidyr::unnest()
unnest_legacy(df, file)
#> # A tibble: 4 x 2
#> value char_vec
#> <dbl> <chr>
#> 1 0.295 <NA>
#> 2 -0.389 A
#> 3 0.0308 <NA>
#> 4 -1.31 <NA>
Created on 2019-10-11 by the reprex package (v0.3.0)