Obtaining data from Spotify Top Charts using spotifyr

Viewed 118

I'm trying to obtain the audio features for the top 200 charts of all of 2017 using the spotifyr package on R, I tried:

days<- spotifycharts::chartdaily()
for (i in days) {
    spotifycharts::chart_top200_daily(region = "global",days = "days[i]")
  }

to obtain the top 200 daily for all of 2017, but I was unable to do it. Can someone help me? :(

1 Answers

It works, if you turn days from tibble into vector:

days <- unlist(chart_daily())

lapply(days[1:3], function(i) chart_top200_daily("global", days = i))

But it parse data badly, so there will be problems with variable names, etc:

# A tibble: 6 x 5
     x1 x2                 x3      note.that.these.figures.are.generated.… x5                 
  <int> <chr>              <chr>                                     <int> <chr>              
1    NA Track Name         Artist                                       NA URL                
2     1 thank u, next      Ariana…                                 8293841 https://open.spoti…
3     2 Taki Taki (with S… DJ Sna…                                 5467625 https://open.spoti…
4     3 MIA (feat. Drake)  Bad Bu…                                 3955367 https://open.spoti…
5     4 Happier            Marshm…                                 3357435 https://open.spoti…
6     5 BAD                XXXTEN…                                 3131745 https://open.spoti…
Related