RE: [R] assignment in lists

About this list Date view Thread view Subject view Author view Attachment view

From: Prof Brian Ripley (ripley@stats.ox.ac.uk)
Date: Fri 27 Jun 2003 - 16:39:34 EST


Message-id: <Pine.LNX.4.44.0306270738050.7550-100000@gannet.stats>

On Fri, 27 Jun 2003, Philippe Grosjean wrote:

> Prof. Brian Ripley wrote:
> >Philippe,
>
> >as.list(NULL) is the same as list(), and that is what I think you should
> >be using in both cases.
>
> OK, thank you.
>
> >However, I do think that either both or neither of your examples should
> >work: my preference would be `neither' but as S allows both it should be
> >`either'.
>
> I agree with you, including on the fact that 'neither' should work. I would
> prefer a language that obliges to declare list components before using them.

I've altered this to work like S (and documented it).

> Experimenting a little bit more around this problem, I got that:
>
> - assigning NULL to a list entry deletes this entry from the list. OK, fine.
> Asking for:
> my.list$non.existing.item gives NULL. Thus, it is consistent. However, if I
> use this:
>
> > a <- list(item1=NULL, item2=NULL)
> > a
> $item1
> NULL
>
> $item2
> NULL
>
> - this is a strange behaviour because the previous command should have
> returned 'list()' in a. Consequently, when I reallocate NULL to either
> 'item1', or 'item2' of 'a', it deletes it:
>
> > a$item1 <- NULL
> > a
> $item2
> NULL
>
> Not an harmfull behaviour, but inconsistent with the rest.

It is in the FAQ, though.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Tue 01 Jul 2003 - 09:12:09 EST