From maechler at stat.math.ethz.ch  Mon Jul 12 11:48:46 2010
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Mon, 12 Jul 2010 11:48:46 +0200
Subject: [Rd] Large discrepancies in the same object being saved
	to	.RData
In-Reply-To: <4C3A36D9.3010400@gmail.com>
References: <62C82B39B8A85E4B95A18F7F7B852F87057236625D@exvic-mbx03.nexus.csiro.au>
	<4C346F1A.8060302@gmail.com>
	<AANLkTimUSBF4mQpc7ZC0kovoBTUiSgwPIiM_acr9ds2H@mail.gmail.com>
	<4C391204.3040601@gmail.com>
	<1BDAE2969943D540934EE8B4EF68F95FB26EB6E6D3@EXNSW-MBX03.nexus.csiro.au>
	<1BDAE2969943D540934EE8B4EF68F95FB26EB66350@EXNSW-MBX03.nexus.csiro.au>
	<4C39DE7C.8060802@acm.org>
	<alpine.LFD.2.00.1007111715220.20108@gannet.stats.ox.ac.uk>
	<4C3A36D9.3010400@gmail.com>
Message-ID: <19514.58622.757461.570952@lynne.math.ethz.ch>

>>>>> "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)
    invisible(.x)
}

--
Martin Maechler, ETH Zurich



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