[R] Scope problems - passing an argument from one function to another (LME) within

Thomas Lumley tlumley at u.washington.edu
Fri Sep 6 17:01:22 CEST 2002


On Fri, 6 Sep 2002, Derek Eder wrote:

> I am having trouble understanding what must be a quite simple rule of
> scope.
>
> In the code example below, the argument to the main function, my.subset,
> would like to be passed to the function LME.  This does not happen
> however.  Curiously, the other argument (my.data) is passed to LME.

Yes.  Modelling and graphics functions with formulas all have slightly
different nonstandard evaluation rules, and it turns out that lme()
doesn't evaluate extra arguments like subset in the parent environment.

There's a description of the nonstandard evaluation rules on
developer.r-project.org, but I will have to rewrite it to include lme,
which I didn't know about.


> This problem goes away with this:  assign("my.subset", my.subset, env =
> sys.frame()).
>
> It works, but it doesn't feel right.  How can I get LME to join the
> scope of the main function?

You can't, not easily.  If you specify a data frame then lme() expects it
to contain all the variables, if you don't specify a data frame then it
looks in the local environment.  help(lme) is consistent with this, but if
you did't know you probably wouldn't interpret it that way.

It turns out that it always looks in the global environment as well, so
you only notice this inside a function

	-thomas


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