From 59355ddf76f78fbb17b0f10172e4196c5e421563 Mon Sep 17 00:00:00 2001 From: annnvv <13822260+annnvv@users.noreply.github.com> Date: Mon, 20 Apr 2020 22:44:56 -0400 Subject: [PATCH] replace httr::GET() with httr::RETRY() --- R/download_kml.R | 2 +- R/get_climate_data.R | 2 +- R/get_ensemble_climate_data.R | 2 +- R/get_historical_data.R | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/download_kml.R b/R/download_kml.R index 3b11200..d967bc1 100644 --- a/R/download_kml.R +++ b/R/download_kml.R @@ -32,7 +32,7 @@ download_kml <- function(locator) { for(i in 1:length(to_download)) { full_url <- paste(base_url, geo_ref, "kml", to_download[i], sep="/") - temp_file <- content(GET(url = full_url), as = "text") + temp_file <- content(RETRY(verb = "GET", url = full_url, terminate_on = c(404)), as = "text") ###Write file to_write<- file(paste(my_path,to_download[i], ".kml", sep=""), open = "w") writeLines(temp_file,to_write) diff --git a/R/get_climate_data.R b/R/get_climate_data.R index 9364f92..89dc132 100644 --- a/R/get_climate_data.R +++ b/R/get_climate_data.R @@ -40,7 +40,7 @@ get_climate_data <- function(locator,geo_type,type, cvar, start, end){ # print(full_url) - res <- GET(full_url) + res <- RETRY("GET", full_url, terminate_on = c(404)) stop_for_status(res) raw_data <- try(content(res, as = "text"), silent = TRUE) if(sum(grep("unexpected",raw_data)) > 0){ diff --git a/R/get_ensemble_climate_data.R b/R/get_ensemble_climate_data.R index 8a3dcad..19a3310 100644 --- a/R/get_ensemble_climate_data.R +++ b/R/get_ensemble_climate_data.R @@ -41,7 +41,7 @@ get_ensemble_climate_data <- function(locator, data_url <- paste(geo_type, type, "ensemble", cvar, start, end, locator, sep="/") extension <- ".json" full_url <- paste(base_url, data_url, extension, sep="") - raw_data <- try(content(GET(full_url), as="text"), silent=TRUE) + raw_data <- try(content(RETRY("GET", full_url, terminate_on = c(404)), as="text"), silent=TRUE) data_out <- jsonlite::fromJSON(raw_data) # json <- jsonlite::fromJSON(raw_data, FALSE) # data_out <- plyr::rbind.fill(lapply(json, function(z) { diff --git a/R/get_historical_data.R b/R/get_historical_data.R index 95dccb5..4a26218 100644 --- a/R/get_historical_data.R +++ b/R/get_historical_data.R @@ -46,7 +46,7 @@ if(geo_type == "basin"){ data_url <- paste(geo_type,"cru",cvar,time_scale,locator,sep="/") extension <- ".json" full_url <- paste(base_url,data_url,extension,sep="") -raw_data <- try(content(GET(full_url),as="text"),silent=T) +raw_data <- try(content(RETRY("GET", full_url, terminate_on = c(404)),as="text"),silent=T) if(sum(grep("unexpected",raw_data)) > 0){ stop(paste("You entered a country for which there is no data. ",locator," is not a country with any data"))