View source: R/misc.utilities.R
persistEval | R Documentation |
A pair of functions paralleling eval()
and evalq()
that make
multiple attempts at evaluating an expression, retrying on error up
to a specified number of attempts, and optionally evaluating
another expression before restarting.
persistEval(
expr,
retries = NVL(getOption("eval.retries"), 5),
beforeRetry,
envir = parent.frame(),
enclos = if (is.list(envir) || is.pairlist(envir)) parent.frame() else baseenv(),
verbose = FALSE
)
persistEvalQ(
expr,
retries = NVL(getOption("eval.retries"), 5),
beforeRetry,
envir = parent.frame(),
enclos = if (is.list(envir) || is.pairlist(envir)) parent.frame() else baseenv(),
verbose = FALSE
)
expr |
an expression to be retried; note the difference
between |
retries |
number of retries to make; defaults to
|
beforeRetry |
if given, an expression that will be evaluated
before each retry if the initial attempt fails; it is evaluated
in the same environment and with the same quoting semantics as
|
envir , enclos |
see |
verbose |
Whether to output retries. |
Results of evaluating expr
, including side-effects such
as variable assignments, if successful in retries
retries.
If expr
returns a "try-error"
object (returned by
try()
), it will be treated as an error. This behavior may
change in the future.
x <- 0
persistEvalQ({if((x<-x+1)<3) stop("x < 3") else x},
beforeRetry = {cat("Will try incrementing...\n")})
x <- 0
e <- quote(if((x<-x+1)<3) stop("x < 3") else x)
persistEval(e,
beforeRetry = quote(cat("Will try incrementing...\n")))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.