I'm trying to go through a list of artists and albums, and get the audio features of each song of each album into a data frame (using spotifyr package). However, in my list, there are some misspellings of the album titles, so I'm trying to use agrep or agrepl to fuzzy match
For example:
library(spotifyr)
library(purrr)
library(dplyr)
library(readr)
Artist <- c("Eminem", "Spiritualized")
Album <- c("Revival", "Pure Phase")
mydata <- data_frame(Artist, Album)
The get_artist_audio_features()
function from spotifyr gives back the audio features for every song from the artist, but I only want songs from some specific album.
get_album_data <- function(x) {
get_artist_audio_features(mydata$Artist[x]) %>%
filter(agrepl(album_name, mydata$Album[x]) == TRUE)}
try_get_album_data <- function(x) {
tryCatch(get_album_data(x), error = function(e) {data.frame()})}
map_df(seq(1,2), try_get_album_data)
When I run this, I get the error:
...argument 'pattern' has length > 1 and only the first element will be used
Any ideas? I know I need to loop through agrepl somehow, but I'm not sure how to implement that within the filter()
function, or if I even need filter()
.