EVOLUTION-MANAGER
Edit File: modify_in.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: Modify a pluck location</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 modify_in {purrr}"><tr><td>modify_in {purrr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Modify a pluck location</h2> <h3>Description</h3> <ul> <li> <p><code>assign_in()</code> takes a data structure and a <a href="pluck.html">pluck</a> location, assigns a value there, and returns the modified data structure. </p> </li> <li> <p><code>modify_in()</code> applies a function to a pluck location, assigns the result back to that location with <code><a href="modify_in.html">assign_in()</a></code>, and returns the modified data structure. </p> </li></ul> <p>The pluck location must exist. </p> <h3>Usage</h3> <pre> modify_in(.x, .where, .f, ...) assign_in(x, where, value) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>.x</code></td> <td> <p>A vector or environment</p> </td></tr> <tr valign="top"><td><code>.where, where</code></td> <td> <p>A pluck location, as a numeric vector of positions, a character vector of names, or a list combining both. The location must exist in the data structure.</p> </td></tr> <tr valign="top"><td><code>.f</code></td> <td> <p>A function to apply at the pluck location given by <code>.where</code>.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Arguments passed to <code>.f</code>.</p> </td></tr> <tr valign="top"><td><code>x</code></td> <td> <p>A vector or environment</p> </td></tr> <tr valign="top"><td><code>value</code></td> <td> <p>A value to replace in <code>.x</code> at the pluck location.</p> </td></tr> </table> <h3>See Also</h3> <p><code><a href="pluck.html">pluck()</a></code> </p> <h3>Examples</h3> <pre> # Recall that pluck() returns a component of a data structure that # might be arbitrarily deep x <- list(list(bar = 1, foo = 2)) pluck(x, 1, "foo") # Use assign_in() to modify the pluck location: assign_in(x, list(1, "foo"), 100) # modify_in() applies a function to that location and update the # element in place: modify_in(x, list(1, "foo"), ~ .x * 200) # Additional arguments are passed to the function in the ordinary way: modify_in(x, list(1, "foo"), `+`, 100) </pre> <hr /><div style="text-align: center;">[Package <em>purrr</em> version 0.3.4 <a href="00Index.html">Index</a>]</div> </body></html>