title: How do I write a function that passes arguments to functions within?
body: <p>I am writing a function in R that will evaluate the fit of a model, but each model takes the same arguments. How can I avoid repeating the same argument to each call to a model?</p>
  
  <p>It is probably more clear here, where the arguments</p>
  
  <pre><code>  data=data,
    na.action = na.exclude,
    subset = block == site)
  </code></pre>
  
  <p>Are repeated.</p>
  
  <pre><code>modelfit &lt;- function(order, response, predictor, site) {
     if(order == 0) {
       m &lt;- lm(response ~ 1, 
               data=data,
               na.action = na.exclude,
               subset = block == site)
     } else if (is.numeric(order)) {
       m &lt;- lm(response ~ poly(predictor, order), 
               data=data,
               na.action = na.exclude,
               subset = block == site)
     } else if (order == 'monod') {
       x&lt;-predictor
       m &lt;- nls(response ~ a*x/(b+x),
                start = list(a=1, b=1),
                data=data,
                na.action = na.exclude,
                subset = block == site)
     } else if (order == 'log') {
       m &lt;- lm(response ~ poly(log(predictor), 1),
               data=data,
               na.action = na.exclude,
                subset = block == site)
     }
     AIC(m)
   }
  </code></pre>
  
  <p>Additional suggestions for better approaches to this question always appreciated.</p>