Skip to content
Prev 55714 / 63421 Next

ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1

I have to agree with Emil here. && and || are short circuited like in C and
C++. That means that

TRUE || c(TRUE, FALSE)
FALSE && c(TRUE, FALSE)

cannot give an error because the second part is never evaluated. Throwing a
warning or error for

c(TRUE, FALSE) || TRUE

would mean that the operator gives a different result depending on the
order of the objects, breaking the symmetry. Also that would be undesirable.

Regarding logical(0): per the documentation, it is indeed so that ||, &&
and isTRUE always return a length-one logical vector. Hence the NA.

On a sidenote: there is no such thing as a scalar in R. What you call
scalar, is really a length-one vector. That seems like a detail, but is
important in understanding why this admittedly confusing behaviour actually
makes sense within the framework of R imho. I do understand your objections
and suggestions, but it would boil down to removing short circuited
operators from R.

My 2 cents.
Cheers
Joris

On Wed, Aug 29, 2018 at 5:03 AM Henrik Bengtsson <henrik.bengtsson at gmail.com>
wrote:

  
    

Thread (15 messages)

Henrik Bengtsson ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1 Aug 28 Emil Bode ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1 Aug 30 Joris Meys ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1 Aug 30 Tóth Dénes ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1 Aug 30 Tóth Dénes ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1 Aug 30 Joris Meys ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1 Aug 30 Emil Bode ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1 Aug 30 Hadley Wickham ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1 Aug 30 William Dunlap ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1 Aug 30 Martin Maechler ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1 Aug 30 Rui Barradas ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1 Aug 30 Joris Meys ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1 Aug 30 Hadley Wickham ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1 Aug 30 Emil Bode ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1 Aug 31 Henrik Bengtsson ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1 Aug 31