title: mutate(across()) with external function that references other variables in current data frame without passing second argument
body: <p>I want to <code>mutate()</code> multiple variables with <code>across()</code></p>
  <ol>
  <li>using a function defined beforehand</li>
  <li>that references other variables in the data frame but</li>
  <li>needs only one argument (the variable to be mutated) and</li>
  <li>does not hard code the environment for those variables inside the function.</li>
  </ol>
  <p>For example, this code will add the variable <code>x</code> to each of <code>y</code> and <code>z</code>:</p>
  <pre><code>library(dplyr)
  
  # Data to modify
  dtmp = tibble(x = 1:4, y = 10, z = 20)
  
  # Function to pass to mutate(across())
  addx = function(col, added){col + added}
  
  # Any of these works
  dtmp %&gt;% mutate(across(c(y,z), addx, added=x))
  dtmp %&gt;% mutate(across(c(y,z), ~addx(.x, x)))
  dtmp %&gt;% mutate(across(c(y,z), function(var){addx(var, x)}))
  </code></pre>
  <p>It is possible to avoid passing a second argument to <code>addx</code> inside <code>mutate(across())</code> by hard-coding the reference to <code>dtmp$x</code> in the global environment:</p>
  <pre><code>addx = function(col){col + dtmp$x}
  dtmp %&gt;% mutate(across(c(y,z), addx))
  </code></pre>
  <p>However, this solution is risky. For example, it would fail to behave as desired if the data frame were grouped (by some 4th variable) before the <code>mutate</code> call because <code>dtmp$x</code> would not be the same length as the subset of <code>y</code> or <code>z</code> within the group.</p>
  <p>It seems like it should be possible to write <code>addx</code> so that we do not have to pass a second argument to it inside <code>mutate(across())</code> and do not have to hard-code <code>dtmp$x</code> inside the function definition. Is this possible? In other words, is there a <code>something(x)</code> that will make the <code>x</code> expression inside the definition of <code>addx()</code> be evaluated in the environment of the current data frame (as defined inside <code>mutate(across(data,...))</code>)?</p>
  <p>The structure of a solution would look like</p>
  <pre><code>addx = function(col){col + Something(x)}
  dtmp %&gt;% mutate(across(c(y,z), addx))
  </code></pre>
  <p><em>Example use case: some functions we might use to modify variables may reference <em>many</em> other variables inside the data frame and those functions may be used many times in the code. Writing out <code>arg1=var1, arg2=var2, arg3=var3,...</code> is a mess.</em></p>