retry: Retry running a function until it succeeds

View source: R/skUtils.R

retryR Documentation

Retry running a function until it succeeds

Description

An expression is executed using [base::try()] and re-run until it raises no more errors or until a maximum number of evaluations is reached. In the latter case, it raises an error of its own.

Usage

retry(expr, n = 5)

Arguments

expr

An expression to try to execute.

n

Maximum number of times to try to run the expression.

Details

This was primarily developed to robustly query websites. Sometimes a query fails or produces output which raises an error; this function issues a retry in such a case.

Value

The output of the expression.

Author(s)

Sercan Kahveci

Examples

k <- 0
retry({k <<- k+1; if(k<4){ stop()}})



Spiritspeak/skMisc documentation built on April 12, 2025, 5:40 a.m.