https://github.com/ijlyttle/warrenr
A persistently verb for purrr
https://github.com/ijlyttle/warrenr
Last synced: 14 days ago
JSON representation
A persistently verb for purrr
- Host: GitHub
- URL: https://github.com/ijlyttle/warrenr
- Owner: ijlyttle
- License: gpl-3.0
- Created: 2017-08-17T12:24:51.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-26T01:55:31.000Z (over 8 years ago)
- Last Synced: 2026-03-31T16:48:12.615Z (3 months ago)
- Language: R
- Size: 19.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
README
# warrenr
The goal of warrenr is to take `persistently()` for a spin. This is based on
@richierocks's [PR to __purrr__](https://github.com/tidyverse/purrr/pull/333), where he proposes `persistently()`. The goal is that this capability be merged into purrr.
## Installation
You can install warrenr from github with:
``` r
# 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.
```R
result <- fragile_api_call(arg1 = "foo", ...)
```
If the call fails, you would like that the call be repeated. Hence the adverb `persistently()`.
```R
persistent_api_call <- warrenr::persistently(fragile_api_call)
```
This returns a new function that will run persistently:
```R
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).