R: attach all of the variables local to the function to global environment after it executes
<p>Suppose I get some function from a client</p>

<pre><code>f &lt;- function(x) {
  if (x) {
    y &lt;- 0
  } else {
    y &lt;- 1
  }
}
</code></pre>

<p>Since I get it from a client I <strong>cannot modify anything within f</strong> (aka substitute &lt;- with &lt;&lt;-, or explicitly attach variables to the global environment).</p>

<p>Is there a way to somehow access all of the variables created within f with whatever values got assigned to them (after I ran it) from the global environment ?
For example: if I ran</p>

<pre><code>f(TRUE)
</code></pre>

<p>I would be able to access a variable "y" in the global environment and see that it is set to "0". I am not worried about overwriting anything in the global environment.</p>

<p>Thanks!</p>