I am currently using a for loop to geocode a large number of addresses using the Googleway package. Initially, I ran into issues with "500 internal server errors" stopping the execution of the loop. I was able to get around this using tryCatch(). However, since this tends to be a transient error, I would like the function to repeat the address that throws the error until it receives a result or hits some arbitrary number of attempts, let's say 10.
Unfortunately, I've found tryCatch() and the documentation associated with it confusing, so I'm at a loss for how to do anything other than get it to throw an error message and move on. Here is my current code:
rugeocoder.fun <- function(addr){
require(googleway)
output <- vector("list", length=length(addr))
tryCatch({
for(i in 1:length(addr)){
output[[i]] <- google_geocode(address=addr[i], key="myapikey", language="ru", simplify=T)
print(i)
}},error=function(e) output[[i]] <- "Error: reattempt")
return(output)
}