Skip to content

Instantly share code, notes, and snippets.

@carlganz
Created November 14, 2017 19:46
Show Gist options
  • Save carlganz/a898142124331723448bd17d9b765dc7 to your computer and use it in GitHub Desktop.
Save carlganz/a898142124331723448bd17d9b765dc7 to your computer and use it in GitHub Desktop.
How to make list-cols?
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
@carlganz
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment