[Rd] The function 'any' (PR#2503)

louisept@pweh.com louisept@pweh.com
Wed Jan 29 01:09:03 2003

Full_Name: Paul Louisell
Version: 1.6.2
OS: Windows NT
Submission from: (NULL) (

There is a slight bug in the function 'any'. Given a logical vector (possibly
including values of 'NA'), the default action of any should be as follows:

(i) at least one value = T should return T
(ii) NO values = T
     (a) at least one value = 'NA' should return 'NA'
     (b) all values = F should return F

The problem is that the default action of 'any' is using the following rule:

(i) at least one value = 'NA' returns 'NA'
(ii) NO values = 'NA'
     (a) at least one value = T returns T
     (b) all values = F returns F

This is illustrated in the code below

> test=1:5
> is.na(test)[5]=T
> test
[1]  1  2  3  4 NA
> any(test==3)
[1] NA
> any(test==5)
[1] NA
> any(test[1:4]==5)
> any(test[1:4]==3)
[1] TRUE

The bug is easily fixed by the user, but someone may want to correct this if
he/she can find time.