[Rd] Logic ("!", "&", ...) on complex

Martin Maechler maechler at stat.math.ethz.ch
Fri Sep 11 12:22:54 CEST 2009


The documentation,  help("!") e.g.,
contains

 > Arguments:

 >     x, y: logical vectors, or objects which can be coerced to such or
 >           for which methods have been written.

and then later

 > Numeric and complex vectors will be coerced to logical values,
 > with zero being false and all non-zero values being true. 

and that is consistent with what  S-plus (3.4, 5.1, 8.0.2)
gives.

However, (nowadays at least) R internally checks and gives an
error for complex arguments,
even though   as.logical(0 + 1i)  works fine.

 > z <- complex(i=1)
 > !z
 Error in !z : invalid argument type
 > !as.logical(z)
 [1] FALSE


I'm proposing to make R's behavior consistent with its
documentation and predecessor.

Martin Maechler



More information about the R-devel mailing list