From 5a48da82710530c563174fc9b2ac3906f6d90a61 Mon Sep 17 00:00:00 2001 From: annnvv <13822260+annnvv@users.noreply.github.com> Date: Mon, 20 Apr 2020 23:04:50 -0400 Subject: [PATCH] replace httr::GET() with httr::RETRY() --- R/get_eurostat_geospatial.R | 8 ++++---- R/get_eurostat_json.R | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/R/get_eurostat_geospatial.R b/R/get_eurostat_geospatial.R index f9503623..281a3b35 100755 --- a/R/get_eurostat_geospatial.R +++ b/R/get_eurostat_geospatial.R @@ -158,7 +158,7 @@ Please check your connection and/or review your proxy settings") if (nuts_level %in% c("0","all")){ url <- paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_4326_LEVL_0.geojson") - resp <- GET(url) + resp <- RETRY("GET", url, terminate_on = c(404)) if (httr::http_error(resp)) { stop(paste("The requested url cannot be found within the get_eurostat_geospatial function:", url)) } else { @@ -168,7 +168,7 @@ Please check your connection and/or review your proxy settings") } if (nuts_level %in% c("1","all")){ url <- paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_4326_LEVL_1.geojson") - resp <- GET(url) + resp <- RETRY("GET", url, terminate_on = c(404)) if (httr::http_error(resp)) { stop(paste("The requested url cannot be found within the get_eurostat_geospatial function:", url)) } else { @@ -177,7 +177,7 @@ Please check your connection and/or review your proxy settings") } } if (nuts_level %in% c("2","all")){ - resp <- GET(paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_4326_LEVL_2.geojson")) + resp <- RETRY("GET", paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_4326_LEVL_2.geojson"), terminate_on = c(404)) if (httr::http_error(resp)) { stop(paste("The requested url cannot be found within the get_eurostat_geospatial function:", url)) } else { @@ -186,7 +186,7 @@ Please check your connection and/or review your proxy settings") } } if (nuts_level %in% c("3","all")){ - resp <- GET(paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_4326_LEVL_3.geojson")) + resp <- RETRY("GET", paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_4326_LEVL_3.geojson"), terminate_on = c(404)) if (httr::http_error(resp)) { stop(paste("The requested url cannot be found within the get_eurostat_geospatial function:", url)) } else { diff --git a/R/get_eurostat_json.R b/R/get_eurostat_json.R index 34237e02..f449b2fb 100755 --- a/R/get_eurostat_json.R +++ b/R/get_eurostat_json.R @@ -68,7 +68,7 @@ get_eurostat_json <- function(id, filters = NULL, # resp <- try(httr::GET(url, ...)) # if (class(resp) == "try-error") { stop(paste("The requested url cannot be found within the get_eurostat_json function:", url)) } - resp <- httr::GET(url) + resp <- httr::RETRY("GET", url, terminate_on = c(404)) if (httr::http_error(resp)) { stop(paste("The requested url cannot be found within the get_eurostat_json function:", url)) }