- Exercise 23.4.4 Item 4: “Explain the following code line-by-line. Why is it interesting? Why does it work for
got_chars
but might not work in general?”
tibble(json = got_chars) |>
unnest_wider(json) |>
select(id, where(is.list)) |>
pivot_longer(
where(is.list),
names_to = "name",
values_to = "value"
) |>
unnest_longer(value)
## # A tibble: 479 × 3
## id name value
## <int> <chr> <chr>
## 1 1022 titles Prince of Winterfell
## 2 1022 titles Lord of the Iron Islands (by law of the green lands)
## 3 1022 aliases Prince of Fools
## 4 1022 aliases Theon Turncloak
## 5 1022 aliases Reek
## 6 1022 aliases Theon Kinslayer
## 7 1022 allegiances House Greyjoy of Pyke
## 8 1022 books A Game of Thrones
## 9 1022 books A Storm of Swords
## 10 1022 books A Feast for Crows
## # ℹ 469 more rows