robustly: Adverb to try calling a function 'n' times before giving up

Description Usage Arguments Value Examples

View source: R/robustly.R

Description

Adverb to try calling a function n times before giving up

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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)

## End(Not run)

FoRTExperiment/ed4forte documentation built on March 21, 2020, 6:54 p.m.