Skip to content

named empty list

3 messages · Hervé Pagès, Martin Maechler

#
Hi,

I just realized that a named empty list is displayed the same
way as an empty list:

   > list(aa=2:5)[0]
   list()
   > list()
   list()

For empty atomic vectors, the print method makes the difference:

   > c(aa=3L)[0]
   named integer(0)
   > integer(0)
   integer(0)

Maybe lists could do that too?

Thanks,
H.


 > sessionInfo()
R version 2.12.0 Under development (unstable) (2010-04-20 r51787)
x86_64-unknown-linux-gnu

locale:
  [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C
  [3] LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8
  [5] LC_MONETARY=C              LC_MESSAGES=en_CA.UTF-8
  [7] LC_PAPER=en_CA.UTF-8       LC_NAME=C
  [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
#
HP> Hi,
    HP> I just realized that a named empty list is displayed the same
    HP> way as an empty list:

    >> list(aa=2:5)[0]
    HP> list()
    >> list()
    HP> list()

    HP> For empty atomic vectors, the print method makes the difference:

    >> c(aa=3L)[0]
    HP> named integer(0)
    >> integer(0)
    HP> integer(0)

    HP> Maybe lists could do that too?

Yes, I agree.  I have had at least one situation in the past
where I had even been confused for a few minutes by this.
I'm about to add it for R-devel [2.12.0] (only; considering it a
new feature).

Martin Maechler, ETH Zurich
#
Thanks Martin.  H.
Martin Maechler wrote: