From p.dalgaard at biostat.ku.dk  Mon Nov 16 18:47:09 2009
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Mon, 16 Nov 2009 18:47:09 +0100
Subject: [Rd] The default behaviour of a missing entry in an environment
In-Reply-To: <b796582f0911160907k4d15751nc4cd14e85a005e93@mail.gmail.com>
References: <D737F65B-A317-44C1-8421-E8DE2D0E0740@nyu.edu>	<4AFDB33D.5010607@stats.uwo.ca>	<971536df0911131539o5d702723u63645580bef5f1f@mail.gmail.com>	<4AFDF822.5050602@stats.uwo.ca>	<971536df0911131626k21bd7cefk391ad821b42170b6@mail.gmail.com>	<4AFDFFFA.9070306@stats.uwo.ca>
	<b796582f0911160907k4d15751nc4cd14e85a005e93@mail.gmail.com>
Message-ID: <4B01901D.4030200@biostat.ku.dk>

Robert Gentleman wrote:
> Hi,
> 
> On Fri, Nov 13, 2009 at 4:55 PM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
>> On 13/11/2009 7:26 PM, Gabor Grothendieck wrote:
>>> On Fri, Nov 13, 2009 at 7:21 PM, Duncan Murdoch <murdoch at stats.uwo.ca>
>>> wrote:
>>>> On 13/11/2009 6:39 PM, Gabor Grothendieck wrote:
>>>>> Note that one should use inherits = FALSE argument on get and exists
>>>>> to avoid returning objects from the parent, the parent of the parent,
>>>>> etc.
>>>> I disagree.  Normally you would want to receive those objects.  If you
>>>> didn't, why didn't you set the parent of the environment to emptyenv()
>>>> when
>>>> you created it?
>>>>
>>> $ does not look into the parent so if you are trying to get those
>>> semantics you must use inherits = FALSE.
>> Whoops, yes.  That's another complaint about $ on environments.
> 
>  That was an intentional choice. AFAIR neither $ nor [[ on
> environments was not meant to mimic get, but rather to work on the
> current environment as if it were a hash-like object. One can always
> get the inherits semantics by simple programming, but under the model
> you seem to be suggesting, preventing such behavior when you don't own
> the environments in question is problematic.
> 
>   Robert

Yes. Also, AFAIR, emptyenv() came later. At the time you couldn't go 
deeper than baseenv().

And at any rate, some of the intended applications are dataframe-like, 
and I don't think you want to preclude use of with() and other forms of 
evaluation in the environment, as in

 > e <- evalq(environment(),airquality)
 > ls(e)
[1] "Day"     "Month"   "Ozone"   "Solar.R" "Temp"    "Wind"

 > evalq(logO3 <- log(Ozone), e) # works fine
 > lm(Ozone~Wind, data=e) # ditto
...

 > parent.env(e) <- emptyenv()
 > evalq(logO3 <- log(Ozone), e)
Error in eval(substitute(expr), envir, enclos) :
   could not find function "<-"
 > lm(Ozone~Wind, data=e)
Error in eval(expr, envir, enclos) : could not find function "list"



-- 
    O__  ---- Peter Dalgaard             ?ster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



[Rd] The default behaviour of a missing entry in an environment
Peter Dalgaard