[R] scope of data in groupedData

Douglas Bates bates at stat.wisc.edu
Mon Nov 19 23:09:43 CET 2001


Thomas Lumley <tlumley at u.washington.edu> writes:

> 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().

Thanks for the suggestion, Thomas.  I'll take a look at it but not, I
regret, immediately.

The reason for the do.call() idiom in the current code is S
compatibility.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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