Re: [R] 'all' inconsistent?

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon 30 Jan 2006 - 18:52:59 EST

On Sun, 29 Jan 2006, Elizabeth Purdom wrote:

> I came across the following behavior, which seems illogical to me.

What did you expect and why?

> I don't know if it is a bug or if I'm missing something:
>
> > all(logical(0))
> [1] TRUE
All the values are true, all none of them.

> > any(logical(0))
> [1] FALSE
There are no true values here.

> > isTRUE(logical(0))
> [1] FALSE
This one I had to look up. The help page says

    'isTRUE(x)' is an abbreviation of 'identical(TRUE,x)'.

so it means isTRUE() is true if and only if the result is a logical vector of length one and value TRUE (and with no attributes) E.g.

> xx <- TRUE
> isTRUE(xx)

[1] TRUE
> names(xx) <- "a"
> isTRUE(xx)

[1] FALSE That could use a little more explanation on the help page.

> This actually came up in practice when I did something like
> > all( names(x) %in% vec )
> as an error-handling, and I was hoping that it would work regardless of
> whether x had names or not.

Depends what `work' means here. It is true if and only if all the names of 'x' are in 'vec', which is presumably not what you wanted.

> I can clearly work around it, but it seemed
> like strange behavior to me.
> Thanks,
> Elizabeth Purdom
> R 2.2.1, Windows XP
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Mon Jan 30 18:59:41 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:14 EST