From hb at stat.berkeley.edu  Tue Aug  3 14:11:21 2010
From: hb at stat.berkeley.edu (Henrik Bengtsson)
Date: Tue, 3 Aug 2010 14:11:21 +0200
Subject: [Rd] Suggestion: make if (x) an error also for length(x) > 1
Message-ID: <AANLkTikd3y+7654JXfHF=f=ZG-uZPoJWqZKEH9rpys+9@mail.gmail.com>

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



[Rd] Suggestion: make if (x) an error also for length(x) > 1
Henrik Bengtsson