data.tables can sometimes have columns that are nested lists. This function will either drop these columns or convert them into character strings.

unlist_dt(dat, drop = FALSE, collapse = ";")

Arguments

dat

data.table

drop

Drop columns that are lists.

collapse

Character to collapse lists with. Used only when drop is FALSE.

Value

data.table

Examples

dat <- data.table::data.table(a=1:3,b=list(1:2,3:4))
#> Warning: Item 2 has 2 rows but longest item has 3; recycled with remainder.
unlist_dt(dat)
#> Unlisting 2 data.table columns.
#>        I     a      b
#>    <int> <int> <char>
#> 1:     1     1    1;2
#> 2:     2     2    3;4
#> 3:     3     3    1;2