title: Parameter passing in R when interior function arguments are dependent on optional parameters
body: <p>I'm working in R and need to pass arguments to a function so that they can be used as arguments when calling another function within the original. In the example below you can see that I'm interested in calling interiorFunc() every time primaryFunc() is called but the value of the first parameter is dependent on the existence of a second parameter. If I declare 'parameter 2' then I want a different set of arguments than if I don't declare 'parameter 2' in the function call. Here is the definition for the interior function:</p>
  
  <pre><code>interiorFunc(data, resp, param1, param2)
  {
    if(missing(param2)) 
    { 
      print(paste("Do analysis without parameter 2 on dataset of size",nrow(data),"with response",resp)
    }else{
      print(paste("Do analysis with parameter 2 on dataset of size",nrow(data),"with response",resp))
    }
  
  }
  </code></pre>
  
  <p>And here is the function that calls it:</p>
  
  <pre><code>primaryFunc &lt;- function(dataset, ...)
  {
    if(parameter 2 has been declared in the call to primaryFunc)
    {
      results &lt;- interiorFunc(dataset, ...)
    }else{
      modifedData &lt;- sample(dataset, 2*dataset, replace = TRUE)
      results &lt;- interiorFunc(modifiedData, ...)
    }
  
    return(results)
  }
  </code></pre>
  
  <p>The function call would either be:</p>
  
  <pre><code>interiorFuncResults &lt;- primaryFunc(dataset, response, parameter1)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>interiorFuncResults &lt;- primaryFunc(dataset, response, parameter1, parameter2)
  </code></pre>
  
  <p>so I need to determine prior to calling the interior function if it's 'parameter2' value has been passed in. Here is a definition of interiorFunc() to make this example reproducible:</p>
  
  <p>Thank you for your help.</p>