Skip to content

assignment in lists

5 messages · Philippe GROSJEAN, Brian Ripley

#
Hello,

I do not understand the following behaviour. Could someone explain me what
happens?
[1] 1 2 3
Error: more elements supplied than there are to replace

Why do I get an error message using list[["item"]], and not using list$item?
Best,

Philippe Grosjean

...........]<(({?<...............<?}))><...............................
 ) ) ) ) )
( ( ( ( (       Dr. Philippe Grosjean
 ) ) ) ) )
( ( ( ( (       LOV, UMR 7093
 ) ) ) ) )      Station Zoologique
( ( ( ( (       Observatoire Oc?anologique
 ) ) ) ) )      BP 28
( ( ( ( (       06234 Villefranche sur mer cedex
 ) ) ) ) )      France
( ( ( ( (
 ) ) ) ) )      tel: +33.4.93.76.38.18, fax: +33.4.93.76.38.34
( ( ( ( (
 ) ) ) ) )      e-mail: phgrosjean at sciviews.org
( ( ( ( (       SciViews project coordinator (http://www.sciviews.org)
 ) ) ) ) )
.......................................................................
#
Ok, I got it. I should have to define a as a list, in order to get a sane
behaviour... That makes sense:
[1] 1 2 3

Best,

Philippe Grosjean

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Philippe Grosjean
Sent: jeudi 26 juin 2003 5:25
To: r-help at stat.math.ethz.ch
Subject: [R] assignment in lists


Hello,

I do not understand the following behaviour. Could someone explain me what
happens?
[1] 1 2 3
Error: more elements supplied than there are to replace

Why do I get an error message using list[["item"]], and not using list$item?
Best,

Philippe Grosjean

...........]<(({?<...............<?}))><...............................
 ) ) ) ) )
( ( ( ( (       Dr. Philippe Grosjean
 ) ) ) ) )
( ( ( ( (       LOV, UMR 7093
 ) ) ) ) )      Station Zoologique
( ( ( ( (       Observatoire Oc?anologique
 ) ) ) ) )      BP 28
( ( ( ( (       06234 Villefranche sur mer cedex
 ) ) ) ) )      France
( ( ( ( (
 ) ) ) ) )      tel: +33.4.93.76.38.18, fax: +33.4.93.76.38.34
( ( ( ( (
 ) ) ) ) )      e-mail: phgrosjean at sciviews.org
( ( ( ( (       SciViews project coordinator (http://www.sciviews.org)
 ) ) ) ) )
.......................................................................

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
#
Philippe,

as.list(NULL) is the same as list(), and that is what I think you should
be using in both cases.  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'.

Brian
On Thu, 26 Jun 2003, Philippe Grosjean wrote:

            

  
    
#
Prof. Brian Ripley wrote:
OK, thank you.
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.
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:
$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:
$item2
NULL

Not an harmfull behaviour, but inconsistent with the rest.
Best,

Philippe Grosjean

...........]<(({?<...............<?}))><...............................
 ) ) ) ) )
( ( ( ( (       Dr. Philippe Grosjean
 ) ) ) ) )
( ( ( ( (       LOV, UMR 7093
 ) ) ) ) )      Station Zoologique
( ( ( ( (       Observatoire Oc?anologique
 ) ) ) ) )      BP 28
( ( ( ( (       06234 Villefranche sur mer cedex
 ) ) ) ) )      France
( ( ( ( (
 ) ) ) ) )      tel: +33.4.93.76.38.18, fax: +33.4.93.76.38.34
( ( ( ( (
 ) ) ) ) )      e-mail: phgrosjean at sciviews.org
( ( ( ( (       SciViews project coordinator (http://www.sciviews.org)
 ) ) ) ) )
.......................................................................
#
On Fri, 27 Jun 2003, Philippe Grosjean wrote:

            
I've altered this to work like S (and documented it).
It is in the FAQ, though.