It seems that it is currently not possible to create a list_of column.
library(tidyr)
df <- tibble(
character = c("Toothless", "Dory"),
metadata = list(
list(colors = "black"),
list(colors = "blue")
)
)
# Goal: colors should be a `list_of<chr>`
df %>%
hoist(metadata,
"colors",
.ptype = list(colors = vctrs::list_of(.ptype = character()))
)
#> Error: Can't convert <character> to <list_of<character>>.
# --> add explicit transformation function via `.transform`
df %>%
hoist(metadata,
"colors",
.ptype = list(colors = vctrs::list_of(.ptype = character())),
.transform = list(
colors = ~ {
vctrs::list_of(!!!.x, .ptype = character())
})
)
#> Error: Can't simplfy 'colors'; contains a nested list
# --> simplify = FALSE doesn't combine to list_of
df %>%
hoist(metadata,
"colors",
.transform = list(
colors = ~ {
vctrs::list_of(!!!.x, .ptype = character())
}),
.simplify = FALSE
)
#> # A tibble: 2 x 2
#> character colors
#> <chr> <list>
#> 1 Toothless <list<chr> [1]>
#> 2 Dory <list<chr> [1]>
Created on 2020-07-16 by the reprex package (v0.3.0)
It seems that it is currently not possible to create a
list_ofcolumn.Created on 2020-07-16 by the reprex package (v0.3.0)