| tibblify | R Documentation |
Transform a nested list into a tibble or a list of objects according to a specification.
tibblify(x, spec = NULL, unspecified = NULL)
x |
( |
spec |
( |
unspecified |
(
|
Fields specifically tagged as tib_unspecified() in the spec (or guessed
as such) will be handled according to the unspecified argument. Fields that
are present in x but not mentioned in the spec are ignored.
Either a tibble or a list, depending on the specification.
Use untibblify() to undo the result of tibblify().
# List of Objects -----------------------------------------------------------
x <- list(
list(id = 1, name = "Tyrion Lannister"),
list(id = 2, name = "Victarion Greyjoy")
)
tibblify(x)
# Provide a specification
spec <- tspec_df(
id = tib_int("id"),
name = tib_chr("name")
)
tibblify(x, spec)
# Object --------------------------------------------------------------------
# Provide a specification for a single object
tibblify(x[[1]], tspec_object(spec))
# Recursive Trees -----------------------------------------------------------
x <- list(
list(
id = 1,
name = "a",
children = list(
list(id = 11, name = "aa"),
list(id = 12, name = "ab", children = list(
list(id = 121, name = "aba")
))
))
)
spec <- tspec_recursive(
tib_int("id"),
tib_chr("name"),
.children = "children"
)
out <- tibblify(x, spec)
out
out$children
out$children[[1]]$children[[2]]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.