R/try.R

Defines functions try.try_try_try

Documented in try.try_try_try

#' Try running a function and get a non-error response n times
#'
#' @param x A function.
#' @param n Number of times to try.
#' @export
#' @examples try.try_try_try(a function)
try.try_try_try <- function(x, n = 3L) {
  response <- "failed"
  attempt <- 1
  while (response == "failed" && attempt <= n) {
    print(sprintf("attempt: %s", attempt))
    attempt <- attempt + 1
    try({ response <- x }, silent = TRUE)
  }
  response
}
dads2busy/dataplumbr documentation built on July 2, 2021, 3:24 a.m.