title: Scope error with update() and glm()
body: <p>I think I incurred in a oddity of <code>R</code>.</p>
  
  <p>I'm building a function <code>do.regression()</code> to manage many type of regressions.</p>
  
  <p>In the case of logistic regression, my function calls out <code>glm2(x, data=model.data, family = family.fun, ...)</code>. The family function for glm() can is an argument of my function, via the family.fun argument. The default is <code>family.fun = binomial</code>.</p>
  
  <p>Inside my function I have a call to another custom function <code>logLikRatio.test &lt;- function (model, model.ref = F )</code> which calculate the log likelihood ratio. Inside this new function I make a call to <code>update()</code> to generate a null model, eg. <code>update(model, . ~ 1)</code>.</p>
  
  <p>Here I get an error:</p>
  
  <pre><code>   Error in glm2(formula = y ~ 1, family = family.fun, data = model.data) : 
     object 'family.fun' not found
  </code></pre>
  
  <p>somehow <code>R</code>expect to find family.fun inside <code>logLikRatio.test()</code>. 
  To test my hypothesis I defined <code>family.fun &lt;- binomial</code>inside it. But I have the error:</p>
  
  <pre><code>Error in is.data.frame(data) : object 'model.data' not found  
  </code></pre>
  
  <p>The same for the argument model.data... <code>R</code> won't traverse the function tree enough to find these variables.</p>
  
  <p>UPDATE:
  I stripped down my functions to isolate the problematic parts:</p>
  
  <pre><code>fake.do.regression &lt;- function(x, data = globalenv(), family.fun = binomial) {
      model.data &lt;- model.frame(x, data)
      model &lt;- glm2(x, data=model.data, family = family.fun)
      fake.logLikRatio.test(model)
  }
  
  fake.logLikRatio.test &lt;- function (model, model.ref = F ) {
      if (model.ref == F) {
  
          #family.fun &lt;- binomial
  
          model.ref &lt;- update(model, . ~ 1, F)
      }
      return( anova(model, model.ref, test="LRT")[2, 'Pr(&gt;Chi)'])
  }
  </code></pre>
  
  <p>Calling fake.do.regression(y ~ x) reproduce the first error; if the <code>#family.fun &lt;- binomial</code> is uncommented, you get the second error.</p>