Adverb to try calling a function `n` times before giving up

robustly(.f, n = 10, timeout = 0.2, silent = TRUE)

Arguments

.f

Function to call.

n

Number of attempts to try

timeout

Timeout between attempts, in seconds

silent

Silence error messages?

Value

Modified version of input function

Examples

# NOT RUN {
rlog <- robustly(log, timeout = 0.3)
try(rlog("fail"))
# }# NOT RUN {
 nc_openr <- robustly(ncdf4::nc_open, n = 10, timeout = 0.5)
 nc <- nc_openr(url)
 # ...or just call the function directly
 nc <- robustly(ncdf4::nc_open, n = 20)(url)
 # Useful in `purrr` maps
 many_vars <- purrr::map(varnames, robustly(ncdf4::ncvar_get), nc = nc)
# }