spotifyr: An R Package for Spotify Data

What it does and how we use it

Najam Hussain

What is spotifyr?

  • An R package that connects to the Spotify Web API
  • Lets you download:
    • Artist data
    • Track data
    • Albums and playlists
    • Audio features (energy, danceability, tempo, etc.)
  • Great for:
    • Music analytics
    • Recommendation models
    • Data visualization projects

Why People Use spotifyr

  • Easy authentication
  • Simple functions for pulling artist/track info
  • Returns tidy data frames, ready for analysis
  • Popular in:
    • Data science projects
    • Music research
    • Visualization challenges
    • Machine learning on audio features

Authenticating With Spotify

To use spotifyr, you need:

  1. A Spotify Developer account
  2. A client ID and secret
  3. Access token generated in R

Code example:

```r library(spotifyr)

Sys.setenv(SPOTIFY_CLIENT_ID = “your_id”) Sys.setenv(SPOTIFY_CLIENT_SECRET = “your_secret”)

access_token <- get_spotify_access_token()

Use Case:

```{library(spotifyr)}

Sys.setenv(SPOTIFY_CLIENT_ID = ‘xxxxxxxxxxxxxxxxxxx’) Sys.setenv(SPOTIFY_CLIENT_SECRET = ‘xxxxxxxxxxxxxxxxxxx’)

access_token <- get_spotify_access_token()

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()

https://www.caitlinhudon.com/posts/2017/12/22/blue-christmas

```

References

  • “Package: Spotifyr 2.2.5.” Spotifyr: R Wrapper for the “Spotify” Web API, charlie86.r-universe.dev/spotifyr. Accessed 16 Dec. 2025. 

  • “Revealjs.” Quarto, quarto.org/docs/presentations/revealjs/. Accessed 16 Dec. 2025. 

  • Thompson C, Antal D, Parry J, Phipps D, Wolff T (2024). spotifyr: R Wrapper for the ‘Spotify’ Web API. R package version 2.2.5, https://github.com/charlie86/spotifyr