R/try_GET_content.R

Defines functions try_GET_content

Documented in try_GET_content

#' Try httr::GET and httr::content function at least 5 times If got errors, save error message.
#'
#' @param url url want to read.
#' @param times trying times.
#'
try_GET_content <- function(url, times = 5){
  ii <- 0
  repeat{
    ii <- ii + 1
    xml <- tryCatch(
      {httr::GET(url) %>% httr::content(as = "parsed", encoding = 'UTF-8')},
      error = function(e){e}
    )
    if(!any(class(xml) == 'error') | ii == times) break
  }; closeAllConnections(); gc(); return(xml)
}
lawine90/datagokR documentation built on Sept. 24, 2020, 9:42 p.m.