Skip to contents

Repeatedly retry a function while it keeps returning FALSE and exit the loop when it returns TRUE

Usage

crew_retry(
  fun,
  args = list(),
  seconds_interval = 1,
  seconds_timeout = 60,
  max_tries = Inf,
  error = TRUE,
  message = character(0),
  envir = parent.frame(),
  assertions = TRUE
)

Arguments

fun

Function that returns FALSE to keep waiting or TRUE to stop waiting.

args

A named list of arguments to fun.

seconds_interval

Nonnegative numeric of length 1, number of seconds to wait between calls to fun.

seconds_timeout

Nonnegative numeric of length 1, number of seconds to loop before timing out.

max_tries

Maximum number of calls to fun to try before giving up.

error

Whether to throw an error on a timeout or max tries.

message

Character of length 1, optional error message if the wait times out.

envir

Environment to evaluate fun.

assertions

TRUE to run assertions to check if arguments are valid, FALSE otherwise. TRUE is recommended for users.

Value

NULL (invisibly).

Examples

crew_retry(fun = function() TRUE)