Inconsistent messages with [[ list indexing (PR#359)
Sat, 4 Dec 1999 15:16:01 +0100 (MET)

R 0.90.0:

> Empl <- list(aa=1, b=2, c=3)
> Empl[[as.numeric(NA)]]
Error in Empl[[as.numeric(NA)]] : subscript out of bounds
> Empl[[as.integer(NA)]]
Error: attempt to select more than one element
> Empl[[as.logical(NA)]]
Error: attempt to select more than one element


(a) None of those messages is appropriate.

(b) At least the first two should be the same.

(c) S gives NULL in each case.

Is there any reason not to follow S here?  If so, I would prefer a
specific error message (`NA cannot be used to select a list element').

The usage

Empl[[ match("a", names(Empl)) ]]

is a very convenient one to defeat partial matching, but the current
behaviour of R defeats it. OK,

Empl[ match("a", names(Empl)) ] [[1]]

works, but this is an ugly hack (and the answer should I believe be the
same as [[ ]]).

Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

r-devel mailing list -- Read
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: