[R] 'with' usage question
Roger D. Peng
rpeng at jhsph.edu
Thu Oct 7 21:28:59 CEST 2004
T/F are not defined in the global environment, rather they are in the
`base' package. That's why you can override them by redefining T/F in
the global environment (or somewhere farther up the search list than
attach() is different because it places variables on the search list
*after* the global environment.
RenE J.V. Bertin wrote:
> On Thu, 07 Oct 2004 13:17:02 -0400, "Roger D. Peng"
> <rpeng at jhsph.edu> wrote regarding "Re: [R] 'with' usage question"
> 8-) I think what's happening is that the function aov.SS1 will look
> up 8-) variables in the environment in which it was *defined*,
> which in your 8-) case (I'm guessing) is the global
> environment/workspace. Therefore, 8-) if `speed' and `Subject' are
> not defined in the global environment, 8-) they will not be found.
> If you take that to the letter, doesn't it mean that attach() and
> detach() couldn't have the effect they have? Which is, in fact and
> if memory serves me well, much like the Pascal 'with' operator. A
> (possible) counter argument: aov.SS1() used T and F as the usual
> abbreviations for TRUE and FALSE: these are defined in the global
> environment. Now my dataframes also contain a variable T: it took
> me quite a while to realise that this variable (which I in fact
> never use directly) would override the T constant/operator and
> cause hard-to-trace error messages.
> I'm trying to find some analogy. with() extends the current
> environment with the variables in the given dataframe, but does not
> create a C-like scope. Rather, it functions more or less like a
> Bourne shell script: the new variables are not 'exported' to be
> available to code evoked from within that new environment, unless
> they were specifically passed as arguments. Which still doesn't
> explain why ls() sees everything when called within a with()
> Anyway, I'd better get back to work before my gray matter
> shortcircuits :)
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the
> posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help