discog
holds a list of 155 items, representing a music
collection stored in the Discogs database and retrieved via their API.
It’s useful for demonstrating capabilities of purrr and tidyr.
library(purrr)
library(tidyr)
library(tibble)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
Here we get just the album names:
discog %>%
map_chr(c("basic_information", "title")) %>%
head()
#> [1] "Demo" "Observant Com El Mon Es Destrueix"
#> [3] "I" "Oído Absoluto"
#> [5] "A Cat's Cause, No Dogs Problem" "Tashme"
Put the discog
list into a list-column and use
tidyr::hoist()
to dig some info out of it.
tibble(disc = discog) %>%
hoist(disc, info = "basic_information") %>%
hoist(info,
title = "title",
year = "year",
label = list("labels", 1, "name"),
artist = list("artists", 1, "name")
) %>%
select(-disc, -info)
#> # A tibble: 155 × 4
#> title year label artist
#> <chr> <int> <chr> <chr>
#> 1 Demo 2015 Tobi Records (2) Mollot
#> 2 Observant Com El Mon Es Destrueix 2013 La Vida Es Un Mus Una B…
#> 3 I 2017 La Vida Es Un Mus S.H.I…
#> 4 Oído Absoluto 2017 La Vida Es Un Mus Rata …
#> 5 A Cat's Cause, No Dogs Problem 2015 Katorga Works Ivy (…
#> 6 Tashme 2019 High Fashion Industries Tashme
#> 7 Demo 2014 Mind Control Records (6) Desgr…
#> 8 Let The Miracles Begin 2015 Not On Label (Phantom Head Se… Phant…
#> 9 Sub Space 2017 Not On Label (Sub Space (2) S… Sub S…
#> 10 Demo 2017 Prescience Tapes Small…
#> # … with 145 more rows