Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

try_again

Try evaluating an expressing multiple times until it succeeds.


Description

Try evaluating an expressing multiple times until it succeeds.

Usage

try_again(times, code)

Arguments

times

Maximum number of attempts.

code

Code to evaluate

Examples

third_try <- local({
  i <- 3
  function() {
    i <<- i - 1
    if (i > 0) fail(paste0("i is ", i))
  }
})
try_again(3, third_try())

testthat

Unit Testing for R

v3.0.2
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre], RStudio [cph, fnd], R Core team [ctb] (Implementation of utils::recover())
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.