[Rd] Large discrepancies in the same object being saved to .RData

Martin Maechler maechler at stat.math.ethz.ch
Mon Jul 12 11:48:46 CEST 2010

>>>>> "DM" == Duncan Murdoch <murdoch.duncan at gmail.com>
>>>>>     on Sun, 11 Jul 2010 17:25:45 -0400 writes:

    DM> On 11/07/2010 1:30 PM, Prof Brian Ripley wrote:


    >>> On 7/10/2010 10:10 PM, Bill.Venables at csiro.au wrote:
    >>>> Well, I have answered one of my questions below.  The hidden
    >>>> environment is attached to the 'terms' component of v1.

    >> Well, not really hidden.  A terms component is a formula
    >> (see ?terms.object), and a formula has an environment
    >> just as a closure does.  In neither case does the print()
    >> method tell you about it -- but ?formula does.

    DM> I've just changed the default print method for formulas to display the 
    DM> environment if it is not globalenv(), which is the rule used for 
    DM> closures as well.  So now in R-devel:

    >> as.formula("y ~ x")
    DM> y ~ x

    DM> as before, but

    >> as.formula("y ~ x", env=new.env())
    DM> y ~ x
    DM> <environment: 01f83400>

I see that our print.formula() actually has not truely fulfilled
our own rule about print methods:

?print   has
 > Description:
 >      ‘print’ prints its argument and returns it _invisibly_ 
 >      ..........

Further, I completely agree that it's good to mention the
environment, however, it can be a nuisance when it's part of a
larger print(.) method, so I'd like allowing to suppress that
and hence I've committed the current

print.formula <- function(x, showEnv = !identical(e, .GlobalEnv), ...)
    e <- environment(.x <- x) ## return(.) original x
    attr(x, ".Environment") <- NULL
    print.default(unclass(x), ...)
    if (showEnv) print(e)

Martin Maechler, ETH Zurich

More information about the R-devel mailing list