Description Usage Arguments Value Examples
Imported from https://github.com/ijlyttle and his warrenr
package. These functions wrap functions so that instead of generating side effects
through printed output, messages, warnings, and errors, they return enhanced
output. They are all adverbs because they modify the action of a verb (a
function).
1 | persistently(.f, quiet = TRUE, max_attempts = 5, wait_seconds = 0.1)
|
.f |
A function, formula, or atomic vector. |
quiet |
Hide errors ( |
max_attempts |
Positive integer. |
wait_seconds |
Positive number. Base multiplier for time in seconds to
wait between attempts. The time increases exponentially, with a wait time
randomly chosen from a uniform distribution between |
wrapped function uses a default value (otherwise
)
whenever an error occurs max_attempts times.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # persistently() makes a function repeatedly try to work
risky_runif <- function(lo = 0, hi = 1) {
y <- stats::runif(1, lo, hi)
if(y < 0.9) {
stop(y, " is too small")
}
y
}
persistent_risky_runif <- persistently(
risky_runif, quiet = FALSE, wait_seconds = 0.01)
## Not run:
set.seed(1)
persistent_risky_runif()
set.seed(3)
persistent_risky_runif()
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.