title: Passing missing argument from function to function in R
body: <p>I’ve learned that it’s common practice to use optional arguments in function and check them with missing()
  (e.g. as discussed in <a href="https://stackoverflow.com/questions/22024082/when-to-using-missing-versus-null-values-for-passing-undefined-function-argument">SO 22024082</a>)</p>
  
  <p>In this example round0 is the optional argument (I know, round0 could be defined as logical).</p>
  
  <pre><code>foo = function(a, round0) {
      a = a * pi
      if(!missing(round0)) round(a)
      else a
  }
  </code></pre>
  
  <p>But what if I call this function from another function, how can I pass “missing”?</p>
  
  <pre><code>bar = function(b) {
      if(b &gt; 10) round1=T
      foo(b, round1)
  }
  </code></pre>
  
  <p>If b &lt; 10 then round1 in bar() is not defined, but is passed to foo anyway. If I modify foo():</p>
  
  <pre><code>foo = function(a, round0) {
      a = a * pi
      print(missing(round0))
      print(round0)
      if(!missing(round0)) round(a)
      else a
  }
  </code></pre>
  
  <p>and run bar(9) the output is:</p>
  
  <pre><code>bar(9)
  [1] FALSE
  Error in print(round0) : object 'round1' not found
  Called from: print(round0)
  </code></pre>
  
  <p>That means: round0 is not missing, but can’t be accessed either?</p>
  
  <p>I don’t want to use different function calls in bar(), if there are several optional arguments in foo(), I would have to write a function call for every missing/not missing - combination of all optional arguments.</p>
  
  <p>Is it possible to pass "missing", or what other solution would apply for this problem?</p>