title: deparse(substitute()) returns function name normally, but function code when called inside for loop
body: <p>I'm a bit surprised by R's behaviour in a very specific case. Let's say I define a function <code>square</code> that returns the square of its argument, like this:</p>
  
  <pre><code>square &lt;- function(x) { return(x^2) }
  </code></pre>
  
  <p>I want to call this function within another function, and I also want to display its name when I do that. I can do that using <code>deparse(substitute())</code>. However, consider the following examples:</p>
  
  <pre><code>ds1 &lt;- function(x) {
    print(deparse(substitute(x)))
  }
  
  ds1(square)
  # [1] "square"
  </code></pre>
  
  <p>This is the expected output, so all is fine. However, if I pass the function wrapped in a list and process it using a for loop, the following happens:</p>
  
  <pre><code>ds2 &lt;- function(x) {
    for (y in x) {
      print(deparse(substitute(y)))
    }
  }
  
  ds2(c(square))
  # [1] "function (x) "   "{"               "    return(x^2)" "}"  
  </code></pre>
  
  <p>Can anybody explain to me why this occurs and how I could prevent it from happening?</p>