reTry: Re-try the call to a function

View source: R/reTry.R

reTryR Documentation

Re-try the call to a function

Description

Tries to call fun. If the call results in an error, the error is logged and after some time it is tried again. If the final try results in an error the function throws an error. Otherwise th result of fun is returned.

Usage

reTry(fun, ..., tries = 1, intSleep = 0, errorLogging = flog.error)

Arguments

fun

(function) a function

...

arguments passed to fun

tries

(numeric > 0) number of tries

intSleep

(numeric >= 0) interval in seconds between tries

errorLogging

(function) a function which is called in case of an error with errorLogging(<try-error>, ...)

Examples

## Something that will fail every once in a while:
try(reTry(
  function() if (runif(1) > 0.5) stop(),
  tries = 2,
  intSleep = 1
))

## Disable logging
noErrorLogging <- function(x, ...) NULL
try(reTry(
  function() stop(),
  errorLogging = noErrorLogging
))


INWT/dbtools documentation built on Oct. 9, 2024, 3:53 p.m.