title: Why can't I assign a function with ifelse in R?
body: <p>In R, when I try to assign a function via <code>ifelse</code>, I get the following error:</p>
  
  <pre><code>&gt; my.func &lt;- ifelse(cond, sqrt, identity)
  Error in rep(yes, length.out = length(ans)) : 
    attempt to replicate an object of type 'builtin'
  </code></pre>
  
  <p>If <code>cond</code> is <code>FALSE</code>, the error looks equivalent, R complains about an</p>
  
  <pre><code>attempt to replicate an object of type 'closure'
  </code></pre>
  
  <p>What can I do to assign one of two functions to a variable and what is going on here?</p>