Skip to content

Commit

Permalink
add rate limiting to batch geocoder
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerke committed May 14, 2024
1 parent 16583c0 commit e8b5753
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]",
role = c("aut", "cre")),
Expand Down
8 changes: 5 additions & 3 deletions R/search.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -365,7 +367,7 @@ mb_batch_geocode <- function(
access_token = access_token,
sf = sf
)
}) %>%
}, .progress = TRUE) %>%
dplyr::select(-ix)

return(geocodes)
Expand Down

0 comments on commit e8b5753

Please sign in to comment.