New spotifyr R Package Release

2.2.1: Thoroughly modernized exception handling, documentation, and some bug fixes

The package is an excellent starting to point for R newbies to try their hands on musicology analysis with a few keystrokes. And of course, it is an essential part of the research infrastructure of musicology worldwide in far more advanced applications.
The package is an excellent starting to point for R newbies to try their hands on musicology analysis with a few keystrokes. And of course, it is an essential part of the research infrastructure of musicology worldwide in far more advanced applications.

I have been a very long-time user of Charlie Thomson’s spotifyr R package, which is probably the most used open-source music analytics software in the world. It provides programmatic access to the Spotify Web API, which contains access to the former Echo Nest quantitative musicology engine.

It is an essential part of the Digital Music Observatory’s streaming analysis and our Listen Local apps designed for our trustworthy AI experiments and independent artist services. I am extremely proud to announce that after a very thorough modernization of the package’s exception handling, documentation, and code dependencies that I did in the last week, the package has passed again the peer-review standards and it is back on CRAN.

The package is an excellent starting to point for R newbies to try their hands on musicology analysis with a few keystrokes. And of course, it is an essential part of the research infrastructure of musicology worldwide in far more advanced applications.

Getting Started

You should start with the README and get your Spotify Web API access tokens to get started.

What Was the Beatles’ Favorite Key?

library(spotifyr)
beatles <- get_artist_audio_features('the beatles')
library(dplyr)
library(purrr)
library(knitr)

beatles %>% 
    count(key_mode, sort: TRUE) %>% 
    head(5) %>% 
    kable()
key_mode n
C major 104
D major 98
G major 82
A major 76
E major 62

Get your most recently played tracks

library(lubridate)

get_my_recently_played(limit: 5) %>% 
    mutate(
        artist.name: map_chr(track.artists, function(x) x$name[1]),
        played_at: as_datetime(played_at)
        ) %>% 
    select(
      all_of(c("track.name", "artist.name", "track.album.name", "played_at"))
      ) %>% 
    kable()
track.name artist.name track.album.name played_at
A Case of You Tristen A Case of You 2021-06-14 09:54:44
Paper Cup Real Estate Paper Cup 2021-06-10 20:20:11
Wrong with You Tristen Wrong with You 2021-06-10 20:17:24
Animal - Edit LUMP Animal 2021-06-10 20:13:21
Streets Of Your Town DOPE LEMON Streets Of Your Town 2021-06-10 18:23:00

That’s about right…

Find Your All Time Favorite Artists

get_my_top_artists_or_tracks(type: 'artists', 
                             time_range: 'long_term', 
                             limit: 5) %>% 
    select(.data$name, .data$genres) %>% 
    rowwise %>% 
    mutate(genres: paste(.data$genres, collapse: ', ')) %>% 
    ungroup %>% 
    kable()
name genres
Japanese Breakfast art pop, bubblegrunge, eugene indie, indie pop, indie rock, philly indie
Haley Bonar melancholia, stomp and holler
Balthazar belgian indie, belgian rock, dutch indie, dutch rock, ghent indie
Buildings Breeding indie fuzzpop
Angus & Julia Stone australian indie folk, indie folk, stomp and holler

What could I say? I travelled Australia listening only to Angus & Julia Stone, the Buildings Breeding have been with me since I discovered them on my first iPod, in one of the first podcasts, the Indiefeed. I created my Kickstarter account back in 2010 to support Haley Bonar’s third album. And the year before I was very much into Japanese Breakfast and Balthazar.

Find your favorite tracks at the moment

get_my_top_artists_or_tracks(type: 'tracks', 
                             time_range: 'short_term', 
                             limit: 5) %>% 
    mutate(
        artist.name: map_chr(artists, function(x) x$name[1])
        ) %>% 
    select(name, artist.name, album.name) %>% 
    kable()
name artist.name album.name
Hot & Heavy Lucy Dacus Hot & Heavy
Sea Urchin Mystic Braves Sea Urchin
Human Freedom Fry Human
Hot Motion Temples Hot Motion
Animal - Edit LUMP Animal

What’s the most joyful Joy Division song?

Let’s take a look at the audio feature has to be valence, a measure of musical positivity.

joy <- get_artist_audio_features('joy division')
joy %>% 
    arrange(-valence) %>% 
    select(.data$track_name, .data$valence) %>% 
    head(5) %>% 
    kable()
track_name valence
Passover - 2020 Digital Master 0.946
Passover - 2007 Remaster 0.941
Colony - 2020 Digital Master 0.829
Colony - 2007 Remaster 0.808
Atrocity Exhibition - 2020 Digital Master 0.790

Now if only there was some way to plot joy…

Joyplot of the emotional rollercoasters that are Joy Division’s albums

Joyplot of the emotional rollercoasters that are Joy Division's albums
Joyplot of the emotional rollercoasters that are Joy Division’s albums

Sentify: A Shiny app

This app, powered by spotifyr, allows you to visualize the energy and valence (musical positivity) of all of Spotify’s artists and playlists.

Dope Stuff Other People Have Done with spotifyr

The coolest thing about making this package has definitely been seeing all the awesome stuff other people have done with it. Here are a few examples:

Exploring the Spotify API with R: A tutorial for beginners, by a beginner, Mia Smith

Blue Christmas: A data-driven search for the most depressing Christmas song, Caitlin Hudon

Sente-se triste quando ouve “Amar pelos dois”? Não é o único (Do you feel sad when you hear “Love for both?” You’re not alone), Rui Barros, Rádio Renascença

Using Data to Find the Angriest Death Grips Song, Evan Oppenheimer

Hierarchical clustering of David Bowie records, Alyssa Goldberg

tayloR, Simran Vatsa

Our Work with spotifyR

A key mission of our Digital Music Observatory, which is our modern, subjective approach on how the future European Music Observatory should look like, is to not only to provide high-quality data on the music economy, the diversity of music, and the audience of music, but also on metadata. The quality and availability, interoperability of metadata (information about how the data should be used) is key to build trustworthy AI systems. We rely on spotifyr to fulfil this mission.

Join our open collaboration Music Data Observatory team as a data curator, developer or business developer.