| try_again | R Documentation |
If you have a flaky test, you can use try_again() to run it a few times
until it succeeds. In most cases, you are better fixing the underlying
cause of the flakeyness, but sometimes that's not possible.
try_again(times, code)
times |
Number of times to retry. |
code |
Code to evaluate. |
usually_return_1 <- function(i) {
if (runif(1) < 0.1) 0 else 1
}
## Not run:
# 10% chance of failure:
expect_equal(usually_return_1(), 1)
# 1% chance of failure:
try_again(1, expect_equal(usually_return_1(), 1))
# 0.1% chance of failure:
try_again(2, expect_equal(usually_return_1(), 1))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.