[R] scope of data in groupedData

Thomas Lumley tlumley at u.washington.edu
Mon Nov 19 22:43:06 CET 2001

On Mon, 19 Nov 2001, Jim Garrett wrote:

> I'm trying to write a function that has a dataframe as
> an argument.  Within the function, I call groupedData
> to create a grouped-data object from the dataframe
> argument.  However, the groupedData function doesn't
> seem to see the data.  I'm guessing it's getting the
> argument name rather than its value, but I'm not
> positive.

Yes, groupedData seems to pass arguments by name and to evaluate the
nmGroupedData call in the local environment, where in your case the name
is not available

This is unusual -- a more common idiom for formula-based functions is

I would think that replacing
  eval(call("nmGroupedData", mCall), parent.frame())
would fix the problem, but I'm not sure what other side-effects this would
have.  You could also make a case for environment(formula) instead of


Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list