I'm trying to write a looped function that extracts data from the discogs api. I've started with writing a function 'a' and it works:
releases <- list()
artists <- list()
artistURL <- "https://api.discogs.com/artists/"
a <- function(artistcode){
for(i in 0:3){
artistset <- fromJSON(paste0(artistURL, artistcode, "/releases?page=", i))
message("Retrieving page ", i)
releases[[i+1]] <- (as.data.frame(artistset$releases.main_release))
artists[[i+1]] <- (as.data.frame(artistset$releases.artist ))
}
return(artistset)
message("Total rows=", dim(artistset[[2]])[1] )
}
x <- a(135872)
Next, I'd like to now add this function into a loop the grabs data for a set of artists who are included in a dataframe, like this:
artistdf <- structure(list(
name = c("Hank Mobley", "Benny Green", "Oscar Peterson", "Art Tatum"),
artistcode = c(135872,96442, 254394, 265634)
), .Names = c("name", "artistcode"), row.names = c(NA,-5L), class = c("tbl_df", "tbl", "data.frame"))
for (j in 0:nrow(artistdf)){
a(artistdf[[j+1, 2]])
}
This is where I get an 'out of bounds' error. I've used some debugging advice, but to no avail. Can anyone offer a solution?