title: R lazy evaluation paradox (R bug?)
body: <p>I have multiple functions handing around arguments that may be missing.</p>
  
  <p>e.g. i have</p>
  
  <pre><code>mainfunction &lt;- function(somearg) {
      mytest(somearg)
      fun &lt;- function() { subfunction(somearg) }
      fun()
  }
  </code></pre>
  
  <p>with the interesting aspect that the only interaction of <code>mytest(somearg)</code> with the arg is that it tests if the argument isn’t missing:</p>
  
  <pre><code>mytest = function(somearg) {
      print(missing(somearg))
  }
  </code></pre>
  
  <p><code>subfunction</code> then again tests if it’s missing and treats it accordingly:</p>
  
  <pre><code>subfunction = function(somearg) {
      if (missing(somearg))
          somearg = NULL
      else
          somearg = matrix(somearg, cols = 2)
      # somearg is used here…
  }
  </code></pre>
  
  <p>the kicker is that, with <code>somearg</code> missing, this doesn’t work: <code>matrix(somearg, cols = 2)</code> throws</p>
  
  <blockquote>
    <p>argument "somearg" is missing, with no default</p>
  </blockquote>
  
  <p>during debugging, i found the following:</p>
  
  <ol>
  <li>at the start of <code>mainfunction</code>, <code>missing(somearg)</code> returns <code>TRUE</code></li>
  <li>in <code>mytest</code>, <code>missing(somearg)</code> returns <code>TRUE</code></li>
  <li>in<code>subfunction</code>, <code>missing(somearg)</code> returns <code>FALSE</code> (!!!!)</li>
  </ol>
  
  <p>therefore the <code>matrix</code> branch is hit, but in reality, <code>somearg</code> <em>is</em> missing, so it fails…</p>
  
  <p>wat.</p>