Skip to content

Commit

Permalink
retry table download
Browse files Browse the repository at this point in the history
fix #60
fix #61
  • Loading branch information
rCarto committed Jun 23, 2020
1 parent eab11a4 commit f4c8552
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
8 changes: 4 additions & 4 deletions R/osrmIsochrone.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ osrmIsochrone <- function(loc, breaks = seq(from = 0,to = 60, length.out = 7),

# slice the grid to make several API calls
lsgr <- nrow(sgrid)
f500 <- lsgr %/% 150
r500 <- lsgr %% 150
f500 <- lsgr %/% 100
r500 <- lsgr %% 100
listDur <- list()
listDest <- list()
# gentle sleeptime for demo server
Expand All @@ -97,8 +97,8 @@ osrmIsochrone <- function(loc, breaks = seq(from = 0,to = 60, length.out = 7),
}
if(f500>0){
for (i in 1:f500){
st <- (i-1) * 150 + 1
en <- i * 150
st <- (i-1) * 100 + 1
en <- i * 100
dmat <- osrmTable(src = loc, dst = sgrid[st:en,], exclude = exclude)
durations <- dmat$durations
listDur[[i]] <- dmat$durations
Expand Down
17 changes: 13 additions & 4 deletions R/osrmTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,19 @@ osrmTable <- function(loc, src = NULL, dst = NULL, exclude = NULL,
osrmLimit(nSrc = nrow(src), nDst = nrow(dst), nreq = nchar(req))

# Get the result
resRaw <- RCurl::getURL(req, useragent = "'osrm' R package")

# Parse the results
res <- jsonlite::fromJSON(resRaw)
bo=0
while(bo!=10){
x = try({
resRaw <- RCurl::getURL(req, useragent = "'osrm' R package")
res <- jsonlite::fromJSON(resRaw)
print("try")
}, silent = T)
if (class(x)=="try-error") {
Sys.sleep(1)
bo <- bo+1
} else
break
}

# Check results
if(is.null(res$code)){
Expand Down

0 comments on commit f4c8552

Please sign in to comment.