Skip to content

Suggestion: make if (x) an error also for length(x) > 1

1 message · Henrik Bengtsson

#
For a while, R has been generating a warning for if (x) when length(x)
Error in if (x) 1 : argument is of length zero
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