I'm using the spotifyr package to scrape spotify audio features for every song of specific albums in my dataset. My issue is that my dataset consists of some artists that are not on spotify -- so they shouldn't be returning any values.
My issue is that when I get to an artist that is not on spotify, I get this error:
Error in bind_rows_(x, .id) : Argument 1 must have names
I've tried wrapping the function in tryCatch to get NA
for each column of the problematic row, but it doesn't seem to work.
Here's an example of my code (FYI, you need to get API access from spotify's website to run the spotifyr code)
library(readr)
library(spotifyr)
library(dplyr)
library(purrr)
Sys.setenv(SPOTIFY_CLIENT_ID = "xxx") #xxx will be from spotify's website
Sys.setenv(SPOTIFY_CLIENT_SECRET = "xxx")
access_token <- get_spotify_access_token()
artist <- c("Eminem", "Chris Stapleton", "Brockhampton", "Big Sean, Metro Boomin")
album <- c("Revival", "From A Room: Volume 2", "SATURATION III", "Double or Nothing")
mydata <- data_frame(artist, album)
get_album_data <- function(x) {
get_artist_audio_features(mydata$artist[x], return_closest_artist = TRUE) %>%
filter(album_name == mydata$album[x])}
try_get_album_data <- function(x) {
tryCatch(get_album_data(x), error = function(e) {NA})}
map_df(seq(1, 4), try_get_album_data)