Learn R Programming

testthat (version 3.1.10)

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

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

Run the code above in your browser using DataLab