Last updated: 2020-06-01

Checks: 7 0

Knit directory: requestival/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20200529) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 8f40292. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    code/_spotify_secrets.R
    Ignored:    data/.DS_Store
    Ignored:    data/raw/.DS_Store
    Ignored:    data/raw/requestival_24_files/
    Ignored:    data/raw/requestival_25_files/
    Ignored:    data/raw/requestival_26_files/
    Ignored:    data/raw/requestival_27_files/
    Ignored:    data/raw/requestival_28_files/
    Ignored:    data/raw/requestival_29_files/
    Ignored:    data/raw/requestival_30_files/
    Ignored:    data/raw/requestival_31_files/
    Ignored:    output/01-scraping.Rmd/
    Ignored:    output/02-tidying.Rmd/
    Ignored:    output/03-augmentation.Rmd/
    Ignored:    output/04-exploration.Rmd/
    Ignored:    renv/library/
    Ignored:    renv/staging/

Untracked files:
    Untracked:  data/raw/requestival_29.html
    Untracked:  data/raw/requestival_30.html
    Untracked:  data/raw/requestival_31.html

Unstaged changes:
    Modified:   data/01-requestival-scraped.tsv
    Modified:   data/02-requestival-tidied.tsv

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/03-augmentation.Rmd) and HTML (docs/03-augmentation.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd fce3c92 Luke Zappia 2020-05-31 Update searching for track ID
html fce3c92 Luke Zappia 2020-05-31 Update searching for track ID
Rmd 3a53852 Luke Zappia 2020-05-31 Add augmentation
html 3a53852 Luke Zappia 2020-05-31 Add augmentation

source(here::here("code", "setup.R"))

Introduction

The tidy we scraped from the HTML pages is now in a nice clean and tidy format but maybe there is some other information we can add to it from other sources?

requestival <- read_tsv(
    PATHS$tidied,
    col_types = cols(
        DateTime     = col_datetime(format = ""),
        Song         = col_character(),
        Artist       = col_character(),
        Release      = col_character(),
        IsUnearthed  = col_logical(),
        UnearthedURL = col_character(),
        SpotifyQuery = col_character(),
        SpotifyURL   = col_character(),
        YouTubeQuery = col_character(),
        YouTubeURL   = col_character()
    )
) %>%
    mutate(DateTime = with_tz(DateTime, "Australia/Sydney"))

Chunk time: 0.04 secs

1 Spotify

We already have search queries for Spotify so maybe we can pull some useful information from their database? Luckily they have a nice API that we can access with the {spotifyr} package. See the {spotifyr} documentation for more details about how this works.

access_token <- get_spotify_access_token(
    client_id     = SPOTIFY_CLIENT_ID,
    client_secret = SPOTIFY_CLIENT_SECRET
)

Chunk time: 0.14 secs

1.1 Track IDs

To get more information about each song we need track IDs which we don’t currently have. The queries we extracted from the Spotify links give use a clue about how to format the search terms but unfortunately we can’t use them directly 😿. Because they were designed for the web spaces and other characters have been replaced with codes (e.g. %20 for space) but the {spotifyr} search function prefers the standard characters. It’s not hard to construct the queries from the information we have though.

For some songs we will get multiple results. Here we try and handle that by first search for the song, artist and release. If there are any results we return the first one. If not we try a simpler search with just the song and artist, and again return the first result.

get_id <- function(Song, Artist, Release, ...) {
    
    # Search for artist, track, album
    query <- glue('artist:"{Artist}" track:"{Song}" album: "{Release}"')
    
    results <- search_spotify(
        query,
        type          = "track",
        market        = "AU",
        authorization = access_token
    ) %>%
        filter(album.release_date_precision == "day")
    
    # Return the earliest result if there are any
    if (nrow(results) > 0) {
        return(results$id[1])
    }
    
    # Otherwise search for just artist and track
    query <- glue('artist:"{Artist}" track:"{Song}"')
    
    results <- search_spotify(
        query,
        type          = "track",
        market        = "AU",
        authorization = access_token
    ) %>%
        filter(album.release_date_precision == "day")
    
    # Return the first result or NA
    if (nrow(results) > 0) {
        return(results$id[1])
    } else {
        return(NA)
    }
}

requestival <- requestival %>%
    mutate(SpotifyID = pmap_chr(requestival, get_id)) %>%
    mutate(HasSpotify = !is.na(SpotifyID))

Chunk time: 2.06 mins

The track IDs are character strings that look something like this: 7tOcPDj3vyopZ404pY6UuP. For our 1187 songs we were able to find 994 IDs. These IDs aren’t very interesting by themselves but we can use them to retrieve other information from the Spotify database.

1.2 Track information

Now that we have track IDs we can get some more information about each of the Requestival songs.

tracks <- requestival %>%
    filter(HasSpotify) %>%
    pull(SpotifyID) %>%
    map_dfr(function(.id) {
        track_info <- get_track(
            .id,
            market        = "AU",
            authorization = access_token
        )
        tibble(
            SpotifyID  = track_info$id,
            AlbumDate  = track_info$album$release_date,
            Duration   = track_info$duration_ms,
            Explicit   = track_info$explicit,
            Popularity = track_info$popularity
        )
    }) %>%
    mutate(
        Duration  = Duration / 1000,
        AlbumDate = ymd(AlbumDate)
    )

tracks

Chunk time: 1.35 mins

A lot of the track information isn’t useful or is redundant with what we already have but I have picked out a few things that might be interesting: the track duration (in seconds), whether it is explicit or not and the Spotify popularity score.

1.3 Audio features

We can also use the Spotify API to retrieve some information about the audio features of each song.

audio <- requestival %>%
    filter(HasSpotify) %>%
    pull(SpotifyID) %>%
    map_dfr(function(.id) {
        audio_features <- get_track_audio_features(
            .id,
            authorization = access_token
        )
    }) %>%
    mutate(IsMajor = mode == 1) %>%
    select(
        SpotifyID    = id,
        IsMajor,
        Loudness     = loudness,
        Tempo        = tempo,
        Valence      = valence,
        Energy       = energy,
        Danceability = danceability,
        Speechiness  = speechiness,
        Acousticness = acousticness,
        Liveness     = liveness
    )

audio

Chunk time: 1.48 mins

Detail about the audio features can be found here but in general they try to provide a numeric description of the track. Some things like loudness, tempo or whether the track is in a major key are simply calculated from the track but others such as “danceability” or “acousticness” are more abstract summaries of what the track sounds like.

Let’s join the information we have downloaded from Spotify to our data scraped from the HTML pages and save it for analysis.

requestival <- requestival %>%
    left_join(tracks, by = "SpotifyID") %>%
    left_join(audio, by = "SpotifyID") %>%
    distinct()

write_tsv(requestival, PATHS$augmented)

requestival

Chunk time: 0.48 secs


sessioninfo::session_info()
─ Session info ───────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 4.0.0 (2020-04-24)
 os       macOS Catalina 10.15.4      
 system   x86_64, darwin17.0          
 ui       X11                         
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       Europe/Berlin               
 date     2020-06-01                  

─ Packages ───────────────────────────────────────────────────────────────────
 ! package     * version date       lib source           
 P assertthat    0.2.1   2019-03-21 [?] CRAN (R 4.0.0)   
 P backports     1.1.7   2020-05-13 [?] CRAN (R 4.0.0)   
 P base64enc     0.1-3   2015-07-28 [?] CRAN (R 4.0.0)   
 P blob          1.2.1   2020-01-20 [?] CRAN (R 4.0.0)   
 P broom         0.5.6   2020-04-20 [?] CRAN (R 4.0.0)   
 P cellranger    1.1.0   2016-07-27 [?] standard (@1.1.0)
 P cli           2.0.2   2020-02-28 [?] CRAN (R 4.0.0)   
 P colorspace    1.4-1   2019-03-18 [?] standard (@1.4-1)
 P conflicted  * 1.0.4   2019-06-21 [?] standard (@1.0.4)
 P crayon        1.3.4   2017-09-16 [?] CRAN (R 4.0.0)   
 P curl          4.3     2019-12-02 [?] CRAN (R 4.0.0)   
 P DBI           1.1.0   2019-12-15 [?] CRAN (R 4.0.0)   
 P dbplyr        1.4.4   2020-05-27 [?] CRAN (R 4.0.0)   
 P digest        0.6.25  2020-02-23 [?] CRAN (R 4.0.0)   
 P dplyr       * 0.8.5   2020-03-07 [?] CRAN (R 4.0.0)   
 P ellipsis      0.3.1   2020-05-15 [?] CRAN (R 4.0.0)   
 P evaluate      0.14    2019-05-28 [?] standard (@0.14) 
 P fansi         0.4.1   2020-01-08 [?] CRAN (R 4.0.0)   
 P forcats     * 0.5.0   2020-03-01 [?] CRAN (R 4.0.0)   
 P fs          * 1.4.1   2020-04-04 [?] CRAN (R 4.0.0)   
 P generics      0.0.2   2018-11-29 [?] standard (@0.0.2)
 P genius        2.2.2   2020-05-28 [?] CRAN (R 4.0.0)   
 P ggplot2     * 3.3.1   2020-05-28 [?] CRAN (R 4.0.0)   
 P git2r         0.27.1  2020-05-03 [?] CRAN (R 4.0.0)   
 P glue        * 1.4.1   2020-05-13 [?] CRAN (R 4.0.0)   
 P gtable        0.3.0   2019-03-25 [?] standard (@0.3.0)
 P haven         2.3.0   2020-05-24 [?] CRAN (R 4.0.0)   
 P here        * 0.1     2017-05-28 [?] standard (@0.1)  
 P hms           0.5.3   2020-01-08 [?] CRAN (R 4.0.0)   
 P htmltools     0.4.0   2019-10-04 [?] standard (@0.4.0)
 P httpuv        1.5.3.1 2020-05-26 [?] CRAN (R 4.0.0)   
 P httr          1.4.1   2019-08-05 [?] standard (@1.4.1)
 P janeaustenr   0.1.5   2017-06-10 [?] CRAN (R 4.0.0)   
 P jsonlite      1.6.1   2020-02-02 [?] CRAN (R 4.0.0)   
 P knitr         1.28    2020-02-06 [?] CRAN (R 4.0.0)   
 P later         1.0.0   2019-10-04 [?] standard (@1.0.0)
 P lattice       0.20-41 2020-04-02 [3] CRAN (R 4.0.0)   
 P lifecycle     0.2.0   2020-03-06 [?] CRAN (R 4.0.0)   
 P lubridate   * 1.7.8   2020-04-06 [?] CRAN (R 4.0.0)   
 P magrittr      1.5     2014-11-22 [?] CRAN (R 4.0.0)   
 P Matrix        1.2-18  2019-11-27 [3] CRAN (R 4.0.0)   
 P memoise       1.1.0   2017-04-21 [?] standard (@1.1.0)
 P modelr        0.1.8   2020-05-19 [?] CRAN (R 4.0.0)   
 P munsell       0.5.0   2018-06-12 [?] standard (@0.5.0)
 P nlme          3.1-147 2020-04-13 [3] CRAN (R 4.0.0)   
 P pillar        1.4.4   2020-05-05 [?] CRAN (R 4.0.0)   
 P pkgconfig     2.0.3   2019-09-22 [?] CRAN (R 4.0.0)   
 P plyr          1.8.6   2020-03-03 [?] CRAN (R 4.0.0)   
 P promises      1.1.0   2019-10-04 [?] standard (@1.1.0)
 P purrr       * 0.3.4   2020-04-17 [?] CRAN (R 4.0.0)   
 P R6            2.4.1   2019-11-12 [?] CRAN (R 4.0.0)   
 P Rcpp          1.0.4.6 2020-04-09 [?] CRAN (R 4.0.0)   
 P readr       * 1.3.1   2018-12-21 [?] standard (@1.3.1)
 P readxl        1.3.1   2019-03-13 [?] standard (@1.3.1)
 P reprex        0.3.0   2019-05-16 [?] standard (@0.3.0)
 P reshape2      1.4.4   2020-04-09 [?] CRAN (R 4.0.0)   
 P rlang         0.4.6   2020-05-02 [?] CRAN (R 4.0.0)   
 P rmarkdown     2.1     2020-01-20 [?] CRAN (R 4.0.0)   
 P rprojroot     1.3-2   2018-01-03 [?] CRAN (R 4.0.0)   
 P rstudioapi    0.11    2020-02-07 [?] CRAN (R 4.0.0)   
 P rvest       * 0.3.5   2019-11-08 [?] standard (@0.3.5)
 P scales        1.1.1   2020-05-11 [?] CRAN (R 4.0.0)   
   sessioninfo   1.1.1   2018-11-05 [3] CRAN (R 4.0.0)   
 P SnowballC     0.7.0   2020-04-01 [?] CRAN (R 4.0.0)   
 P spotifyr    * 2.1.1   2019-07-13 [?] CRAN (R 4.0.0)   
 P stringi       1.4.6   2020-02-17 [?] CRAN (R 4.0.0)   
 P stringr     * 1.4.0   2019-02-10 [?] CRAN (R 4.0.0)   
 P tibble      * 3.0.1   2020-04-20 [?] CRAN (R 4.0.0)   
 P tidyr       * 1.1.0   2020-05-20 [?] CRAN (R 4.0.0)   
 P tidyselect    1.1.0   2020-05-11 [?] CRAN (R 4.0.0)   
 P tidytext      0.2.4   2020-04-17 [?] CRAN (R 4.0.0)   
 P tidyverse   * 1.3.0   2019-11-21 [?] standard (@1.3.0)
 P tokenizers    0.2.1   2018-03-29 [?] CRAN (R 4.0.0)   
 P vctrs         0.3.0   2020-05-11 [?] CRAN (R 4.0.0)   
 P whisker       0.4     2019-08-28 [?] standard (@0.4)  
 P withr         2.2.0   2020-04-20 [?] CRAN (R 4.0.0)   
 P workflowr     1.6.2   2020-04-30 [?] CRAN (R 4.0.0)   
 P xfun          0.14    2020-05-20 [?] CRAN (R 4.0.0)   
 P xml2        * 1.3.2   2020-04-23 [?] CRAN (R 4.0.0)   
 P yaml          2.2.1   2020-02-01 [?] CRAN (R 4.0.0)   

[1] /Users/luke.zappia/Documents/Projects/requestival/renv/library/R-4.0/x86_64-apple-darwin17.0
[2] /private/var/folders/rj/60lhr791617422kqvh0r4vy40000gn/T/RtmpQWp4dI/renv-system-library
[3] /Library/Frameworks/R.framework/Versions/4.0/Resources/library

 P ── Loaded and on-disk path mismatch.

Chunk time: 0.26 secs

LS0tCnRpdGxlOiAiQXVnbWVudGF0aW9uIgpvdXRwdXQ6IHdvcmtmbG93cjo6d2Zsb3dfaHRtbAplZGl0b3Jfb3B0aW9uczoKICBjaHVua19vdXRwdXRfdHlwZTogY29uc29sZQotLS0KCmBgYHtyIHNldHVwLCBjYWNoZSA9IEZBTFNFfQpzb3VyY2UoaGVyZTo6aGVyZSgiY29kZSIsICJzZXR1cC5SIikpCmBgYAoKIyBJbnRyb2R1Y3Rpb24gey51bm51bWJlcmVkfQoKVGhlIHRpZHkgd2Ugc2NyYXBlZCBmcm9tIHRoZSBIVE1MIHBhZ2VzIGlzIG5vdyBpbiBhIG5pY2UgY2xlYW4gYW5kIHRpZHkgZm9ybWF0CmJ1dCBtYXliZSB0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tIHRvIHJldHJpZXZlIG90aGVyIGluZm9ybWF0aW9uIApmcm9tIHRoZSBTcG90aWZ5IGRhdGFiYXNlLgoKIyMgVHJhY2sgaW5mb3JtYXRpb24KCk5vdyB0aGF0IHdlIGhhdmUgdHJhY2sgSURzIHdlIGNhbiBnZXQgc29tZSBtb3JlIGluZm9ybWF0aW9uIGFib3V0IGVhY2ggb2YgdGhlClJlcXVlc3RpdmFsIHNvbmdzLgoKYGBge3IgdHJhY2staW5mb30KdHJhY2tzIDwtIHJlcXVlc3RpdmFsICU+JQogICAgZmlsdGVyKEhhc1Nwb3RpZnkpICU+JQogICAgcHVsbChTcG90aWZ5SUQpICU+JQogICAgbWFwX2RmcihmdW5jdGlvbiguaWQpIHsKICAgICAgICB0cmFja19pbmZvIDwtIGdldF90cmFjaygKICAgICAgICAgICAgLmlkLAogICAgICAgICAgICBtYXJrZXQgICAgICAgID0gIkFVIiwKICAgICAgICAgICAgYXV0aG9yaXphdGlvbiA9IGFjY2Vzc190b2tlbgogICAgICAgICkKICAgICAgICB0aWJibGUoCiAgICAgICAgICAgIFNwb3RpZnlJRCAgPSB0cmFja19pbmZvJGlkLAogICAgICAgICAgICBBbGJ1bURhdGUgID0gdHJhY2tfaW5mbyRhbGJ1bSRyZWxlYXNlX2RhdGUsCiAgICAgICAgICAgIER1cmF0aW9uICAgPSB0cmFja19pbmZvJGR1cmF0aW9uX21zLAogICAgICAgICAgICBFeHBsaWNpdCAgID0gdHJhY2tfaW5mbyRleHBsaWNpdCwKICAgICAgICAgICAgUG9wdWxhcml0eSA9IHRyYWNrX2luZm8kcG9wdWxhcml0eQogICAgICAgICkKICAgIH0pICU+JQogICAgbXV0YXRlKAogICAgICAgIER1cmF0aW9uICA9IER1cmF0aW9uIC8gMTAwMCwKICAgICAgICBBbGJ1bURhdGUgPSB5bWQoQWxidW1EYXRlKQogICAgKQoKdHJhY2tzCmBgYAoKQSBsb3Qgb2YgdGhlIHRyYWNrIGluZm9ybWF0aW9uIGlzbid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