Unnest list-columns.

unnest(
  .df,
  ...,
  keep_empty = FALSE,
  .drop = TRUE,
  names_sep = NULL,
  names_repair = "unique"
)

Arguments

.df

A data.table

...

Columns to unnest If empty, unnests all list columns. tidyselect compatible.

keep_empty

Return NA for any NULL elements of the list column

.drop

Should list columns that were not unnested be dropped

names_sep

If NULL, the default, the inner column names will become the new outer column names.

If a string, the name of the outer column will be appended to the beginning of the inner column names, with names_sep used as a separator.

names_repair

Treatment of duplicate names. See ?vctrs::vec_as_names for options/details.

Examples

df1 <- tidytable(x = 1:3, y = 1:3)
df2 <- tidytable(x = 1:2, y = 1:2)
nested_df <-
  data.table(
    a = c("a", "b"),
    frame_list = list(df1, df2),
    vec_list = list(4:6, 7:8)
  )

nested_df %>%
  unnest(frame_list)
#> # A tidytable: 5 × 3
#>   a         x     y
#>   <chr> <int> <int>
#> 1 a         1     1
#> 2 a         2     2
#> 3 a         3     3
#> 4 b         1     1
#> 5 b         2     2

nested_df %>%
  unnest(frame_list, names_sep = "_")
#> # A tidytable: 5 × 3
#>   a     frame_list_x frame_list_y
#>   <chr>        <int>        <int>
#> 1 a                1            1
#> 2 a                2            2
#> 3 a                3            3
#> 4 b                1            1
#> 5 b                2            2

nested_df %>%
  unnest(frame_list, vec_list)
#> # A tidytable: 5 × 4
#>   a         x     y vec_list
#>   <chr> <int> <int>    <int>
#> 1 a         1     1        4
#> 2 a         2     2        5
#> 3 a         3     3        6
#> 4 b         1     1        7
#> 5 b         2     2        8