df <- tibble(
id = 1L,
name = "a",
children = list(
tibble(
id = 11:12,
name = c("b", "c"),
children = list(
NULL,
tibble(
id = 121:122,
name = c("d", "e")
)
)
)
)
)
unnest_tree(
df,
id_col = "id",
child_col = "children",
level_to = "level",
parent_to = "parent",
ancestors_to = "ancestors"
)
Run the code above in your browser using DataLab