[R] Is it a bug in list() behavior?

Tony Plate tplate at blackmesacapital.com
Mon Mar 24 20:45:18 CET 2003


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



More information about the R-help mailing list