Re: [Rd] The default behaviour of a missing entry in an environment

From: Robert Gentleman <rgentlem_at_fhcrc.org>
Date: Mon, 16 Nov 2009 09:07:23 -0800

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@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

>
> Duncan Murdoch
>

>>
>>> x <- 3
>>> e <- new.env()
>>> "x" %in% names(e)
>>
>> [1] FALSE
>>>
>>> get("x", e) # oops
>>
>> [1] 3
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



-- 
Robert Gentleman
rgentlem_at_gmail.com

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Mon 16 Nov 2009 - 17:10:15 GMT

This archive was generated by hypermail 2.2.0 : Mon 16 Nov 2009 - 21:10:26 GMT