aRrgh icon indicating copy to clipboard operation
aRrgh copied to clipboard

Truth value of vectors should be explained

Open tdsmith opened this issue 12 years ago • 0 comments

issue raised in #8:

Furthermore, you forget dealing with vectors in the check:

> if (1:3) print('yes') else print('no')
[1] "yes"
Warning message:
In if (1:3) print("yes") else print("no") :
  the condition has length > 1 and only the first element will be used
> if (identical(TRUE, as.logical(1:3))) print('yes') else print('no')
[1] "no"

So invoking as.logical is not going to help you to test for the truth value of an "arbitrary not-necessarily-already-boolean value", only if it's already a scalar.

tdsmith avatar Oct 29 '13 06:10 tdsmith