From e8b57539e0273ff471290e46421e261ebdd59734 Mon Sep 17 00:00:00 2001 From: Kyle Walker Date: Tue, 14 May 2024 11:22:26 -0500 Subject: [PATCH] add rate limiting to batch geocoder --- DESCRIPTION | 4 ++-- R/search.R | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1619b08..4d3cec1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: mapboxapi Type: Package Title: R Interface to 'Mapbox' Web Services -Date: 2024-05-10 -Version: 0.6 +Date: 2024-05-14 +Version: 0.6.1 Authors@R: c(person(given = "Kyle", family = "Walker", email = "kyle@walker-data.com", role = c("aut", "cre")), diff --git a/R/search.R b/R/search.R index dcfa6c0..fac20c1 100644 --- a/R/search.R +++ b/R/search.R @@ -336,12 +336,14 @@ mb_batch_geocode <- function( "i" = "The limit for Mapbox's free tier is 100,000 geocodes per month. Beyond that, you will incur charges.", "i" = "Please visit https://www.mapbox.com/pricing for more information.")) } else { - data$ix <- c(0, rep(1:(nrow(origins) - 1) %/% 1000)) + mb_batch_geocode_limited <- purrr::slowly(mb_batch_geocode, rate = rate_delay(60)) + + data$ix <- c(0, rep(1:(nrow(data) - 1) %/% 1000)) geocodes <- data %>% split(~ix) %>% purrr::map_dfr(function(x) { - mapboxapi::mb_batch_geocode( + mb_batch_geocode_limited( data = x, search_column = search_column, address_line1 = address_line1, @@ -365,7 +367,7 @@ mb_batch_geocode <- function( access_token = access_token, sf = sf ) - }) %>% + }, .progress = TRUE) %>% dplyr::select(-ix) return(geocodes)