title: undefined variable in unreached ifelse clause causes error
body: <p>I have two nested <code>ifelse</code> statements in a function.  When I call the function, it fails because a variable in the last <code>else</code> clause is undefined - even if that clause is not reached.</p>
  
  <pre><code>x &lt;- factor(c("a", "b", "c", "d"))
  
  h &lt;- "hi"
  l &lt;- "lo"
  </code></pre>
  
  <p>Now undefined variable <code>m</code> is never used, but this produces an error:</p>
  
  <pre><code>ifelse(as.numeric(x) &gt; 2, h,
         ifelse(as.numeric(x) &lt; 3, l, m))
  </code></pre>
  
  <blockquote>
    <p>Error in ifelse(as.numeric(x) &lt; 3, l, m) : object 'm' not found</p>
  </blockquote>
  
  <p>Even though all four values of <code>x</code> satisfy the first two <code>if</code> conditions:</p>
  
  <pre><code>&gt; sum(as.numeric(x) &gt; 2 | as.numeric(x) &lt; 3)
  [1] 4
  </code></pre>
  
  <p>Edit: I intentionally haven't defined <code>m</code> in this example, but I'd like to know how this is evaluated such that R looks for <code>m</code> when the last clause is never reached.</p>