From ripley@stats.ox.ac.uk  Sat Dec  4 14:16:01 1999
From: ripley@stats.ox.ac.uk (ripley@stats.ox.ac.uk)
Date: Sat, 4 Dec 1999 15:16:01 +0100 (MET)
Subject: Inconsistent messages with [[ list indexing (PR#359)
Message-ID: <199912041416.PAA12018@pubhealth.ku.dk>

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

Now,

(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,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
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 http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


Inconsistent messages with [[ list indexing (PR#359)
ripley@stats.ox.ac.uk