R loop to wait specified time

2.4k Views Asked by At

I'm working with the Discogs API and am running into an issue with rate limiting. I have a loop to to cycle through all of my release id's and then pull back further release information. The rate limit is 25 calls every 60 seconds, but I can't seem to find a way to limit the call from within httr. I'm wondering if perhaps a for loop would be more ideal?

I have pasted my code below:

releasedata <- lapply(as.list(collection$release_id), function(obj){
  url <- httr::GET(paste0("https://api.discogs.com/releases/", obj))
  url <- rjson::fromJSON(rawToChar(url$content))
  data.frame(release_id = obj, 
             label = url$label[[1]]$name %||% NA,
             year = url$year %||% NA, 
             title = url$title %||% NA, 
             artist_name = url$artist[[1]]$name %||% NA, 
             styles = url$styles[[1]] %||% NA,
             genre = url$genre[[1]] %||% NA,
             average_note = url$community$rating$average %||% NA, 
             votes = url$community$rating$count %||% NA, 
             want = url$community$want %||% NA, 
             have = url$community$have %||% NA, 
             lowest_price = url$lowest_price %||% NA, 
             country = url$country %||% NA)
}) %>% do.call(rbind, .) %>% 
  unique()

If anybody can recommend an appropriate loop for this, I'd appreciate the help.

0

There are 0 best solutions below