tdsmith / aRrgh

A newcomer's (angry) guide to data types in R
Other
306 stars 14 forks source link

Truth value of vectors should be explained #10

Open tdsmith opened 11 years ago

tdsmith commented 11 years ago

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.