r - Is it possible to control the speed of the lapply function? -
i wrote script geocode list of addresses using r , google maps, exceeds google's 10 queries per second speed limit. slow down 5 queries per second.
my function constructs url, , call functions using do.call, rbind, , lapply create geocoded dataset.
geoc <- function(address){ out <- trycatch({ url <- "http://maps.google.com/maps/api/geocode/json" response <- get(url,query=list(sensor="false",address1=address)) json <- fromjson(content(response,type="text")) loc <- json$results[[1]]$geometry$location return(c(address1=address, long=loc$lng, lat=loc$lat)) }) return(out) } result <- do.call(rbind,lapply(as.character(sample$location),geoc))
is there way slow down 5 queries per second? works great if i'm geocoding 5 or 10 @ time, on there throws google errors.
thanks!
use sys.sleep
wait given time, proceed. not able use r session else, can have multiple r sessions running @ same time not prevent working in r session.
Comments
Post a Comment