-
Notifications
You must be signed in to change notification settings - Fork 422
Closed
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behaviorrectangling 🗄️converting deeply nested lists into tidy data framesconverting deeply nested lists into tidy data frames
Description
Adapting the Toothless & Dory example, but where I've removed the films metadata for Toothless. When I hoist() or unnest_wider(), films is destined to become a list-column. I think the entry for Dory should be NULL, not an unspecified vector of length 1. Or maybe even an unspecified vector of length 0? Or a character vector of length 0?
library(tidyverse)
df <- tibble(
character = c("Toothless", "Dory"),
metadata = list(
list(
species = "dragon",
color = "black"
),
list(
species = "clownfish",
color = "blue",
films = c("Finding Nemo", "Finding Dory")
)
)
)
df
#> # A tibble: 2 x 2
#> character metadata
#> <chr> <list>
#> 1 Toothless <named list [2]>
#> 2 Dory <named list [3]>
df %>%
hoist(metadata, films = "films")
#> # A tibble: 2 x 3
#> character films metadata
#> <chr> <list> <list>
#> 1 Toothless <???> <named list [2]>
#> 2 Dory <chr [2]> <named list [2]>
(df2 <- df %>%
unnest_wider(metadata))
#> # A tibble: 2 x 4
#> character species color films
#> <chr> <chr> <chr> <list>
#> 1 Toothless dragon black <???>
#> 2 Dory clownfish blue <chr [2]>
df2$films
#> [[1]]
#> <unspecified> [1]
#>
#> [[2]]
#> [1] "Finding Nemo" "Finding Dory"
lengths(df2$films)
#> [1] 1 2Created on 2019-11-20 by the reprex package (v0.3.0.9001)
Metadata
Metadata
Assignees
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behaviorrectangling 🗄️converting deeply nested lists into tidy data framesconverting deeply nested lists into tidy data frames