There are use cases where it seems like it would be useful to have some control over the column names that unnest() produces, for example if there are multiple columns of data frames with the same columns:
df <- dplyr::data_frame(
x = 1:3,
y = list(data_frame(a = runif(3), b = runif(3))),
z = list(data_frame(a = runif(3), b = runif(3)))
)
tidyr::unnest(df)
# Source: local data frame [9 x 5]
#
# x a b a b
# (int) (dbl) (dbl) (dbl) (dbl)
#1 1 0.1828750 0.6893545 0.4887932 0.6530871
#2 1 0.5282101 0.1400115 0.5172123 0.4216703
#3 1 0.2047363 0.9180311 0.5185549 0.8593084
#4 2 0.1828750 0.6893545 0.4887932 0.6530871
#5 2 0.5282101 0.1400115 0.5172123 0.4216703
#6 2 0.2047363 0.9180311 0.5185549 0.8593084
#7 3 0.1828750 0.6893545 0.4887932 0.6530871
#8 3 0.5282101 0.1400115 0.5172123 0.4216703
#9 3 0.2047363 0.9180311 0.5185549 0.8593084
Maybe something like .combine, that combines the nested column names:
tidyr::unnest(df, .combine = TRUE)
# Source: local data frame [9 x 5]
#
# x y.a y.b z.a z.b
# (int) (dbl) (dbl) (dbl) (dbl)
#1 1 0.1828750 0.6893545 0.4887932 0.6530871
#2 1 0.5282101 0.1400115 0.5172123 0.4216703
#3 1 0.2047363 0.9180311 0.5185549 0.8593084
#4 2 0.1828750 0.6893545 0.4887932 0.6530871
#5 2 0.5282101 0.1400115 0.5172123 0.4216703
#6 2 0.2047363 0.9180311 0.5185549 0.8593084
#7 3 0.1828750 0.6893545 0.4887932 0.6530871
#8 3 0.5282101 0.1400115 0.5172123 0.4216703
#9 3 0.2047363 0.9180311 0.5185549 0.8593084
Or supplying a function for how to combine them?
There are use cases where it seems like it would be useful to have some control over the column names that
unnest()produces, for example if there are multiple columns of data frames with the same columns:Maybe something like
.combine, that combines the nested column names:Or supplying a function for how to combine them?