R/try_read_json.R

Defines functions try_read_json

Documented in try_read_json

#' Try jsonlite::read_json function at least 5 times If got errors, save error message.
#'
#' @param url url want to read.
#' @param times trying times.
#'
try_read_json <- function(url, times = 5){
  ii <- 0
  repeat{
    ii <- ii + 1
    xml <- tryCatch(
      {jsonlite::read_json(url)},
      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.