EVOLUTION-MANAGER
Edit File: poke_vars.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: Replace or get current variables</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 poke_vars {tidyselect}"><tr><td>poke_vars {tidyselect}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Replace or get current variables</h2> <h3>Description</h3> <p>Variables are made available to <a href="language.html">select helpers</a> by registering them in a special placeholder. </p> <ul> <li> <p><code>scoped_vars()</code> changes the current variables and sets up a function exit hook that automatically restores the previous variables once the current function returns. </p> </li> <li> <p><code>with_vars()</code> takes an expression to be evaluated in a variable context. </p> </li> <li> <p><code>poke_vars()</code> changes the contents of the placeholder with a new set of variables. It returns the previous variables invisibly and it is your responsibility to restore them after you are done. This is for expert use only. </p> </li> <li> <p><code>peek_vars()</code> returns the variables currently registered. </p> </li> <li> <p><code>has_vars()</code> returns <code>TRUE</code> if a variable context has been set, <code>FALSE</code> otherwise. </p> </li></ul> <h3>Usage</h3> <pre> poke_vars(vars) scoped_vars(vars, frame = caller_env()) with_vars(vars, expr) has_vars() </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>vars</code></td> <td> <p>A character vector of variable names.</p> </td></tr> <tr valign="top"><td><code>frame</code></td> <td> <p>The frame environment where the exit hook for restoring the old variables should be registered.</p> </td></tr> <tr valign="top"><td><code>expr</code></td> <td> <p>An expression to be evaluated within the variable context.</p> </td></tr> </table> <h3>Value</h3> <p>For <code>poke_vars()</code> and <code>scoped_vars()</code>, the old variables invisibly. For <code>peek_vars()</code>, the variables currently registered. </p> <h3>See Also</h3> <p>peek_vars </p> <h3>Examples</h3> <pre> poke_vars(letters) peek_vars() # Now that the variables are registered, the helpers can figure out # the locations of elements within the variable vector: all_of(c("d", "z")) # In a function be sure to restore the previous variables. An exit # hook is the best way to do it: fn <- function(vars) { old <- poke_vars(vars) on.exit(poke_vars(old)) all_of("d") } fn(letters) fn(letters[3:5]) # The previous variables are still registered after fn() was # called: peek_vars() # It is recommended to use the scoped variant as it restores the # state automatically when the function returns: fn <- function(vars) { scoped_vars(vars) starts_with("r") } fn(c("red", "blue", "rose")) # The with_vars() helper makes it easy to pass an expression that # should be evaluated in a variable context. Thanks to lazy # evaluation, you can just pass the expression argument from your # wrapper to with_vars(): fn <- function(expr) { vars <- c("red", "blue", "rose") with_vars(vars, expr) } fn(starts_with("r")) </pre> <hr /><div style="text-align: center;">[Package <em>tidyselect</em> version 1.1.0 <a href="00Index.html">Index</a>]</div> </body></html>