hoist {tidyr} | R Documentation |
Hoist values out of list-columns
Description
hoist()
allows you to selectively pull components of a list-column
into their own top-level columns, using the same syntax as purrr::pluck()
.
Learn more in vignette("rectangle")
.
Usage
hoist(
.data,
.col,
...,
.remove = TRUE,
.simplify = TRUE,
.ptype = NULL,
.transform = NULL
)
Arguments
.data |
A data frame. |
.col |
< |
... |
< The column names must be unique in a call to |
.remove |
If |
.simplify |
If |
.ptype |
Optionally, a named list of prototypes declaring the desired output type of each component. Alternatively, a single empty prototype can be supplied, which will be applied to all components. Use this argument if you want to check that each element has the type you expect when simplifying. If a |
.transform |
Optionally, a named list of transformation functions applied to each component. Alternatively, a single function can be supplied, which will be applied to all components. Use this argument if you want to transform or parse individual elements as they are extracted. When both |
See Also
Other rectangling:
unnest_longer()
,
unnest_wider()
,
unnest()
Examples
df <- tibble(
character = c("Toothless", "Dory"),
metadata = list(
list(
species = "dragon",
color = "black",
films = c(
"How to Train Your Dragon",
"How to Train Your Dragon 2",
"How to Train Your Dragon: The Hidden World"
)
),
list(
species = "blue tang",
color = "blue",
films = c("Finding Nemo", "Finding Dory")
)
)
)
df
# Extract only specified components
df %>% hoist(metadata,
"species",
first_film = list("films", 1L),
third_film = list("films", 3L)
)