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
Could it be considered to make list_rbind() recursive?
I often encounter nested lists that need to be "dataframed", for instance:
library(tidyverse)
x=list(
a=list(a1=sample_n(iris, 1), a2=sample_n(iris, 1)),
b=list(b1=sample_n(iris, 1), b2=sample_n(iris, 1))
)
list_rbind(x)
#> Error in `list_rbind()`:#> ! Each element of `x` must be either a data frame or `NULL`.#> i Elements 1 and 2 are not.
In this simple case, this can be dealt with using map(), although it is less elegant:
However, in more complicated cases, it can get more complex to get a single dataframe in the end:
x2=list(
a= sample_n(iris, 1),
b=list(b1=sample_n(iris, 1), b2=sample_n(iris, 1))
)
x2 %>% map(list_rbind) %>% list_rbind()
#> Error in `map()`:#> i In index: 1.#> i With name: a.#> Caused by error in `.f()`:#> ! `x` must be a list, not a <data.frame> object.
Also, in more deep nested lists, mapping several times can get tedious and error-prone.
Is this something that would belong in purrr?
Maybe with a recursive=TRUE option?
The text was updated successfully, but these errors were encountered:
Hi,
Could it be considered to make
list_rbind()
recursive?I often encounter nested lists that need to be "dataframed", for instance:
In this simple case, this can be dealt with using
map()
, although it is less elegant:However, in more complicated cases, it can get more complex to get a single dataframe in the end:
Also, in more deep nested lists, mapping several times can get tedious and error-prone.
Is this something that would belong in purrr?
Maybe with a
recursive=TRUE
option?The text was updated successfully, but these errors were encountered: