Henrik Bengtsson
2010-Aug-03 12:11 UTC
[Rd] Suggestion: make if (x) an error also for length(x) > 1
For a while, R has been generating a warning for if (x) when length(x)> 1. With length(x) == 0, we get an error.> x <- logical(0) > if (x) 1;Error in if (x) 1 : argument is of length zero> x <- logical(1) > if (x) 1; > x <- logical(2) > if (x) 1;Warning message: In if (x) 1 : the condition has length > 1 and only the first element will be used Time to make the length(x) > 1 case an error to? Is there any sane programming reason why it should work as if (x[1]) with a warning? How many bugs propagate because of this? /Henrik