[R] Is it a bug in list() behavior?
Uwe Ligges
ligges at statistik.uni-dortmund.de
Mon Mar 24 23:04:35 CET 2003
Tony Plate wrote:
>
> At Monday 07:31 PM 3/24/2003 +0100, Uwe Ligges wrote:
> >Tony Plate wrote:
> >>As wolski/Eryk's example shows, it seems that "[[" for lists accepts abbreviations, whereas "[" does not. Is this intended? (This is a difference from S-plus - both "[" and "[[" for lists accept abbreviations in S-plus (V6.1 for Windows at least.)
> >
> >The general subscripting operator [] doesn't support abbreviations at all. I don't know of any reference that states [] supports partial matching of character strings.
>
> My copy of the Blue Book, Section 11.4.1 (p357 of 1996 printing) seems to pretty strongly imply that "[" supports partial matching of character strings (it gives S-code for handling of indices, and uses pmatch for handling character indices in extraction contexts). However, I certainly wouldn't advocate adding this to R if all existing software works without this capability. It does seem worth documenting in place where beginning users can find it though.
>
> >>The name returned by "[" for a non-existent element of a list also seems of dubious correctness.
> >>
> >>>list(abc=123)[["a"]]
> >>[1] 123
> >>
> >>>list(abc=123)["a"]
> >>$"NA"
> >>NULL
> >
> >Everything as expected from my point of view. Do you mean the "NA" is "dubious"?
>
> Yes, the string "NA" as a name is of dubious correctness. The behavior of "[" with vectors is more what I would have expected:
> > c(abc=123)["ab"]
> <NA>
> NA
> >
>
> -- Tony Plate
Two last points:
- related to Tony Plate's mail: I don't have any S books at home (where
I am right now).
- related to Spencer Graves' mail: Transportability is not really an
issue. Or do you want to write code relying on partial matching? I
won't-or try to avoid it, at least. Example:
LL <- list(a1=1, a2=2)
LL$a # Hmmm ... partial matching can be quite dangerous!
I leave this topic open now.
Uwe
More information about the R-help
mailing list