[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
  m<-match.call()
  m[[1]]<-as.name("someotherfunction")
  eval(m,sys.frame(sys.parent()))


I would think that replacing
  do.call("nmGroupedData",mCall)
with
  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
parent.frame().


	-thomas

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