Why do logical operators negate their argument when there is only one argument in R?

160 views Asked by At

When passing only a single vector to the logical and/or operator, the operator negates the argument:

> x = c(F,T,T)
> `&`(x)
[1]  TRUE FALSE FALSE

> `|`(x)
[1]  TRUE FALSE FALSE

To make the logical operator work as idempotent, one needs to pass a single element vector as the second argument:

> `&`(x,T)
[1] FALSE  TRUE  TRUE

> `|`(x,F)
[1] FALSE  TRUE  TRUE

Why do the logical operators negate their argument when there is only one argument passed?

1

There are 1 answers

1
Thomas On BEST ANSWER

This was modified in R 3.2.1 as a result of a bug report. As you've pointed out, the previous behavior made little sense:

enter image description here