EVOLUTION-MANAGER
Edit File: as_mapper.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: Convert an object into a mapper function</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 as_mapper {purrr}"><tr><td>as_mapper {purrr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Convert an object into a mapper function</h2> <h3>Description</h3> <p><code>as_mapper</code> is the powerhouse behind the varied function specifications that most purrr functions allow. It is an S3 generic. The default method forwards its arguments to <code><a href="../../rlang/html/as_function.html">rlang::as_function()</a></code>. </p> <h3>Usage</h3> <pre> as_mapper(.f, ...) ## S3 method for class 'character' as_mapper(.f, ..., .null, .default = NULL) ## S3 method for class 'numeric' as_mapper(.f, ..., .null, .default = NULL) ## S3 method for class 'list' as_mapper(.f, ..., .null, .default = NULL) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>.f</code></td> <td> <p>A function, formula, or vector (not necessarily atomic). </p> <p>If a <strong>function</strong>, it is used as is. </p> <p>If a <strong>formula</strong>, e.g. <code>~ .x + 2</code>, it is converted to a function. There are three ways to refer to the arguments: </p> <ul> <li><p> For a single argument function, use <code>.</code> </p> </li> <li><p> For a two argument function, use <code>.x</code> and <code>.y</code> </p> </li> <li><p> For more arguments, use <code>..1</code>, <code>..2</code>, <code>..3</code> etc </p> </li></ul> <p>This syntax allows you to create very compact anonymous functions. </p> <p>If <strong>character vector</strong>, <strong>numeric vector</strong>, or <strong>list</strong>, it is converted to an extractor function. Character vectors index by name and numeric vectors index by position; use a list to index by position and name at different levels. If a component is not present, the value of <code>.default</code> will be returned.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Additional arguments passed on to methods.</p> </td></tr> <tr valign="top"><td><code>.default, .null</code></td> <td> <p>Optional additional argument for extractor functions (i.e. when <code>.f</code> is character, integer, or list). Returned when value is absent (does not exist) or empty (has length 0). <code>.null</code> is deprecated; please use <code>.default</code> instead.</p> </td></tr> </table> <h3>Examples</h3> <pre> as_mapper(~ . + 1) as_mapper(1) as_mapper(c("a", "b", "c")) # Equivalent to function(x) x[["a"]][["b"]][["c"]] as_mapper(list(1, "a", 2)) # Equivalent to function(x) x[[1]][["a"]][[2]] as_mapper(list(1, attr_getter("a"))) # Equivalent to function(x) attr(x[[1]], "a") as_mapper(c("a", "b", "c"), .default = NA) </pre> <hr /><div style="text-align: center;">[Package <em>purrr</em> version 0.3.4 <a href="00Index.html">Index</a>]</div> </body></html>