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

2009-11-16 Thread Peter Dalgaard
Robert Gentleman wrote: Hi, On Fri, Nov 13, 2009 at 4:55 PM, Duncan Murdoch wrote: On 13/11/2009 7:26 PM, Gabor Grothendieck wrote: On Fri, Nov 13, 2009 at 7:21 PM, Duncan Murdoch wrote: On 13/11/2009 6:39 PM, Gabor Grothendieck wrote: Note that one should use inherits = FALSE argument on

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

2009-11-16 Thread Duncan Murdoch
On 11/16/2009 12:07 PM, Robert Gentleman wrote: Hi, On Fri, Nov 13, 2009 at 4:55 PM, Duncan Murdoch wrote: On 13/11/2009 7:26 PM, Gabor Grothendieck wrote: On Fri, Nov 13, 2009 at 7:21 PM, Duncan Murdoch wrote: On 13/11/2009 6:39 PM, Gabor Grothendieck wrote: Note that one should use in

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

2009-11-16 Thread Robert Gentleman
Hi, On Fri, Nov 13, 2009 at 4:55 PM, Duncan Murdoch wrote: > On 13/11/2009 7:26 PM, Gabor Grothendieck wrote: >> >> On Fri, Nov 13, 2009 at 7:21 PM, Duncan Murdoch >> wrote: >>> >>> On 13/11/2009 6:39 PM, Gabor Grothendieck wrote: Note that one should use inherits = FALSE argument on g

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

2009-11-13 Thread Duncan Murdoch
On 13/11/2009 7:26 PM, Gabor Grothendieck wrote: On Fri, Nov 13, 2009 at 7:21 PM, Duncan Murdoch 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, et

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

2009-11-13 Thread Gabor Grothendieck
On Fri, Nov 13, 2009 at 7:21 PM, Duncan Murdoch 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

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

2009-11-13 Thread Duncan Murdoch
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

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

2009-11-13 Thread Gabor Grothendieck
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. On Fri, Nov 13, 2009 at 2:27 PM, Duncan Murdoch wrote: > On 11/13/2009 2:03 PM, Trishank Karthik Kuppusamy wrote: >> >> Greetings everyone, >> >> I have

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

2009-11-13 Thread Duncan Murdoch
On 11/13/2009 3:03 PM, Trishank Karthik Kuppusamy wrote: On Nov 13, 2009, at 2:47 PM, Duncan Murdoch wrote: Inconsistent with what happens for lists: > x <- list() > x$b NULL and attributes: > attr(x, "b") NULL Ah, I see. I would claim that the same argument for default safety should apply

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

2009-11-13 Thread Trishank Karthik Kuppusamy
Hello Henrik, On Nov 13, 2009, at 3:42 PM, Henrik Bengtsson wrote: > If you develop your own code you can add your own behavior by > "extending" the environment class. I put "extending" in quotation > marks, because 'environment' is one of few classes you should *not* > extend from in the regula

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

2009-11-13 Thread Henrik Bengtsson
If you develop your own code you can add your own behavior by "extending" the environment class. I put "extending" in quotation marks, because 'environment' is one of few classes you should *not* extend from in the regular S3 (and S4?) sense, at least that was the case a few years ago. You can se

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

2009-11-13 Thread Trishank Karthik Kuppusamy
On Nov 13, 2009, at 2:47 PM, Duncan Murdoch wrote: > Inconsistent with what happens for lists: > > > x <- list() > > x$b > NULL > > and attributes: > > > attr(x, "b") > NULL Ah, I see. I would claim that the same argument for default safety should apply here too. > It is already a little st

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

2009-11-13 Thread Duncan Murdoch
On 11/13/2009 2:39 PM, Trishank Karthik Kuppusamy wrote: Hello Duncan, Thanks for your reply. On Nov 13, 2009, at 2:27 PM, Duncan Murdoch wrote: You get the same behaviour when asking for a nonexistent element of a list, or a nonexistent attribute. If you want stricter checking, don't use

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

2009-11-13 Thread Trishank Karthik Kuppusamy
Hello Duncan, Thanks for your reply. On Nov 13, 2009, at 2:27 PM, Duncan Murdoch wrote: > You get the same behaviour when asking for a nonexistent element of a list, > or a nonexistent attribute. If you want stricter checking, don't use $, use > get(): > > > get("b", e) > Error in get("b",

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

2009-11-13 Thread Duncan Murdoch
On 11/13/2009 2:03 PM, Trishank Karthik Kuppusamy wrote: Greetings everyone, I have a question about the default behaviour of a missing entry in an environment. Let us look at the following sequence of R statements: e <- new.env() e$a <- 1 e$a [1] 1 e$b NULL I think I understand the lo

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

2009-11-13 Thread Trishank Karthik Kuppusamy
Greetings everyone, I have a question about the default behaviour of a missing entry in an environment. Let us look at the following sequence of R statements: > e <- new.env() > e$a <- 1 > e$a [1] 1 > e$b NULL > I think I understand the logic for returning NULL to a missing entry in an enviro