EVOLUTION-MANAGER
Edit File: faq-adverbs-export.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: Best practices for exporting adverb-wrapped functions</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 faq-adverbs-export {purrr}"><tr><td>faq-adverbs-export {purrr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Best practices for exporting adverb-wrapped functions</h2> <h3>Description</h3> <p>Functions like <code><a href="insistently.html">insistently()</a></code>, <code><a href="safely.html">safely()</a></code>, <code><a href="insistently.html">slowly()</a></code>, and <code><a href="safely.html">quietly()</a></code> help resolve challenging issues in programming. For example, <code><a href="safely.html">safely()</a></code> modifies a function to return both an error and a result. These functions work by returning an enhanced version of the original function. They are often called <strong>adverb</strong> functions and are typically named with an informative prefix such as <code>safe_</code> or <code>insist_.</code> For instance, an insistent variant of <code>scrape_data()</code> created with <code>insistently()</code> might be called <code>insist_scrape_data()</code>. </p> <p>Exporting functions created with purrr adverbs in your package requires some precautions. Because the functions created by adverbs contain internal purrr code, creating them once and for all when the package is built might cause problems when purrr is updated. Instead, the function must be created by the purrr adverb each time the package is loaded in memory via the <code><a href="../../base/html/ns-hooks.html">.onLoad()</a></code> hook of the package. This prevents the generated functions to contain outdated internal purrr code (which could even refer to functions that no longer exist in the purrr namespace). </p> <p>An example if provided below for <code>insist</code>, but it would be very similar for functions generated by other adverbs.</p> <pre>#' My function insist_my_function <- function(...) "dummy" my_function <- function(...) { # Implementation } .onLoad <- function(lib, pkg) { insist_my_function <<- purrr::insistently(my_function) } </pre> <hr /><div style="text-align: center;">[Package <em>purrr</em> version 0.3.4 <a href="00Index.html">Index</a>]</div> </body></html>