title: Scoping in custom lattice functions (group argument)
body: <p>Please consider this function:</p>
  
  <pre><code>tf &lt;- function(formula = NULL, data = NULL, groups = NULL) {
  
      grv &lt;- eval(substitute(groups), data, environment(formula)) # the values
      grn &lt;- as.character(match.call()$groups) # the name
      gr &lt;- match.call()$groups # unquoted name
  
      p &lt;- xyplot(formula, data, # draws the data but not in groups
  # Try these options:
  #   p &lt;- xyplot(formula, data, groups, # can't find 'cat2' 
  #   p &lt;- xyplot(formula, data, groups = data[,grn], # can't fine grn
  #   p &lt;- xyplot(formula, data, groups = grv, # can't find grv
          panel = function(x, y) {
              panel.stripplot(x, y, jitter.data = TRUE, pch = 20)
              }
              )
      p
      }
  </code></pre>
  
  <p>Which you can run with:</p>
  
  <pre><code>tf(formula = mpg~vs, groups = am, data = mtcars)
  </code></pre>
  
  <p>What am I doing wrong in passing the <code>groups</code> argument to <code>xyplot</code> - why can't it be found? I can't figure out how it wants the <code>group</code> information.  Thanks.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>@agstudy's answer is very helpful, but if I add the panel function as in the original example, the groups are still not recognized (no grouping, but no error occurs either):</p>
  
  <pre><code>tf &lt;- function(formula = NULL, data = NULL, groups = NULL) {
      ll &lt;- as.list(match.call(expand.dots = FALSE)[-1])
      p &lt;- xyplot(as.formula(ll$formula), 
                data = eval(ll$data), 
                groups = eval(ll$groups),
                  panel = function(x, y) {
                  panel.stripplot(x, y, jitter.data = TRUE, pch = 20)
                  }
                  )
      p
      }
  </code></pre>
  
  <p>Something is still missing... Thanks.</p>