[R] Environment of a formula

Martin Maechler maechler at stat.math.ethz.ch
Mon Feb 7 09:35:09 CET 2005


>>>>> "Gabor" == Gabor Grothendieck <ggrothendieck at myway.com>
>>>>>     on Mon, 7 Feb 2005 04:39:40 +0000 (UTC) writes:

     Adrian Baddeley <adrian <at> maths.uwa.edu.au> writes:
     : I want to equip a data frame with an attribute 
     : which specifies how to plot some of the columns. 
     : 
     : Up to now we have been doing this by giving the data frame 
     : a `formula' attribute, that can be passed to plot.formula.
     : 
     : For example
     :       dat <- data.frame(x=1:100,y=runif(100),z=100:1)
     :       attr(dat, "plotme") <- (z ~ x)
     :       ......
     :       ......
     :       if(missing(desiredformula))
     : 	desiredformula <- attr(dat, "plotme")
     :       plot(desiredformula, data=dat)
     : 
     : We just got bitten by the fact that a formula object has a `.Environment'
     : attribute, which may be huge, depending on the environment
     : in which the formula was created. In the example above there is
     : no upper limit on the size of the object 'dat' !!!!
     : That is, environment(attr(dat, "plotme")) could be huge.

    Gabor> Do you mean that if fo is the formula then ls(environment(fo))
    Gabor> has many large components?   I don't understand why that would
    Gabor> be a problem.

maybe Adrian save()s that data.frame susequently?
Then, I assume the environment will copied.
In all(?) other circumstances that should only be a pointer and
not really use much memory.

Martin




More information about the R-help mailing list