EVOLUTION-MANAGER
Edit File: insistently.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Transform a function to make it run insistently or slowly</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for insistently {purrr}"><tr><td>insistently {purrr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Transform a function to make it run insistently or slowly</h2> <h3>Description</h3> <ul> <li> <p><code>insistently()</code> takes a function and modifies it to retry a given amount of time on error. </p> </li> <li> <p><code>slowly()</code> takes a function and modifies it to wait a given amount of time between each call. </p> </li></ul> <p>The number and rate of attempts is determined by a <a href="rate-helpers.html">rate</a> object (by default a jittered exponential backoff rate for <code>insistently()</code>, and a constant rate for <code>slowly()</code>). </p> <p>If you would like to include a function created with <code>safely</code>, <code>slowly</code>, or <code>insistently</code> in a package, see <a href="faq-adverbs-export.html">faq-adverbs-export</a>. </p> <h3>Usage</h3> <pre> insistently(f, rate = rate_backoff(), quiet = TRUE) slowly(f, rate = rate_delay(), quiet = TRUE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>f</code></td> <td> <p>A function to modify.</p> </td></tr> <tr valign="top"><td><code>rate</code></td> <td> <p>A <a href="rate-helpers.html">rate</a> object determining the waiting time.</p> </td></tr> <tr valign="top"><td><code>quiet</code></td> <td> <p>If <code>FALSE</code>, prints a message displaying how long until the next request.</p> </td></tr> </table> <h3>See Also</h3> <p><code><a href="../../httr/html/RETRY.html">httr::RETRY()</a></code> is a special case of <code><a href="insistently.html">insistently()</a></code> for HTTP verbs. <code><a href="rate-helpers.html">rate_backoff()</a></code> and <code><a href="rate-helpers.html">rate_delay()</a></code> for creating custom backoff rates. <code><a href="rate_sleep.html">rate_sleep()</a></code> for the function powering <code>insistently()</code> and <code>slowly()</code>. <code><a href="safely.html">safely()</a></code> for another useful function operator. </p> <h3>Examples</h3> <pre> # For the purpose of this example, we first create a custom rate # object with a low waiting time between attempts: rate <- rate_delay(0.1) # slowly() causes a function to sleep for a given time between calls: slow_runif <- slowly(~ runif(1), rate = rate, quiet = FALSE) map(1:5, slow_runif) # insistently() makes a function repeatedly try to work risky_runif <- function(lo = 0, hi = 1) { y <- runif(1, lo, hi) if(y < 0.9) { stop(y, " is too small") } y } # Let's now create an exponential backoff rate with a low waiting # time between attempts: rate <- rate_backoff(pause_base = 0.1, pause_min = 0.005, max_times = 4) # Modify your function to run insistently. insistent_risky_runif <- insistently(risky_runif, rate, quiet = FALSE) set.seed(6) # Succeeding seed insistent_risky_runif() set.seed(3) # Failing seed try(insistent_risky_runif()) # You can also use other types of rate settings, like a delay rate # that waits for a fixed amount of time. Be aware that a delay rate # has an infinite amount of attempts by default: rate <- rate_delay(0.2, max_times = 3) insistent_risky_runif <- insistently(risky_runif, rate = rate, quiet = FALSE) try(insistent_risky_runif()) # insistently() and possibly() are a useful combination rate <- rate_backoff(pause_base = 0.1, pause_min = 0.005) possibly_insistent_risky_runif <- possibly(insistent_risky_runif, otherwise = -99) set.seed(6) possibly_insistent_risky_runif() set.seed(3) possibly_insistent_risky_runif() </pre> <hr /><div style="text-align: center;">[Package <em>purrr</em> version 0.3.4 <a href="00Index.html">Index</a>]</div> </body></html>