tibblify: Rectangle a nested list

View source: R/tibblify.R

tibblifyR Documentation

Rectangle a nested list

Description

Rectangle a nested list

Usage

tibblify(x, spec = NULL, names_to = NULL, unspecified = NULL)

Arguments

x

A nested list.

spec

A specification how to convert x. Generated with tspec_row() or tspec_df().

names_to

Deprecated. Use tspec_df(.names_to) instead.

unspecified

A string that describes what happens if the specification contains unspecified fields. Can be one of

  • "error": Throw an error.

  • "inform": Inform.

  • "drop": Do not parse these fields.

  • "list": Parse an unspecified field into a list.

Value

Either a tibble or a list, depending on the specification

See Also

Use untibblify() to undo the result of tibblify().

Examples

# 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]]

tibblify documentation built on Nov. 16, 2022, 5:07 p.m.