Skip to content

ijlyttle/warrenr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

warrenr

The goal of warrenr is to take persistently() for a spin. This is based on @richierocks's PR to purrr, where he proposes persistently(). The goal is that this capability be merged into purrr.

Installation

You can install warrenr from github with:

# install.packages("devtools")
devtools::install_github("ijlyttle/warrenr")

Example

Let's say you have an API call that does not work 100% of the time, due to vagaries of the network, etc.

result <- fragile_api_call(arg1 = "foo", ...)

If the call fails, you would like that the call be repeated. Hence the adverb persistently().

persistent_api_call <- warrenr::persistently(fragile_api_call)

This returns a new function that will run persistently:

result <- persistent_api_call(arg1 = "foo", ...)

There are arguments for max_attempts (default: 5) and wait_seconds (default: 0.1 s). Should the function throw an error, each subsequent call will wait twice the amount of time as it previously waited (plus some random fuzz).

About

A persistently verb for purrr

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages