Created
November 14, 2017 19:46
-
-
Save carlganz/a898142124331723448bd17d9b765dc7 to your computer and use it in GitHub Desktop.
How to make list-cols?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(tibble) | |
myList <- list( | |
list( | |
id = 1, | |
name = "A", | |
sublist = list( | |
a=1,b=2 | |
) | |
), | |
list(id = 2, | |
name = "B", | |
sublist= list( | |
a=3,c=4 | |
) | |
) | |
) | |
### This gets me what I want, but doesn't seem tidyverse enough | |
lapply(myList, function(x) { | |
x[vapply(x,is.list,logical(1))] <- lapply(x[vapply(x,is.list,logical(1))], function(i) { | |
list(i) | |
}) | |
as_tibble(x) | |
}) %>% bind_rows |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd tackle it like this:
At some point in the future, we'll probably have something like:
And some tool for guessing the types so you can just do
read_tree(myList)
and get something reasonable