[Rd] ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1
Martin Maechler
m@echler @ending from @t@t@m@th@ethz@ch
Thu Aug 30 17:58:17 CEST 2018
>>>>> Joris Meys
>>>>> on Thu, 30 Aug 2018 14:48:01 +0200 writes:
> On Thu, Aug 30, 2018 at 2:09 PM Dénes Tóth
> <toth.denes using kogentum.hu> wrote:
>> Note that `||` and `&&` have never been symmetric:
>>
>> TRUE || stop() # returns TRUE stop() || TRUE # returns an
>> error
>>
>>
> Fair point. So the suggestion would be to check whether x
> is of length 1 and whether y is of length 1 only when
> needed. I.e.
> c(TRUE,FALSE) || TRUE
> would give an error and
> TRUE || c(TRUE, FALSE)
> would pass.
> Thought about it a bit more, and I can't come up with a
> use case where the first line must pass. So if the short
> circuiting remains and the extra check only gives a small
> performance penalty, adding the error could indeed make
> some bugs more obvious.
I agree "in theory".
Thank you, Henrik, for bringing it up!
In practice I think we should start having a warning signalled.
I have checked the source code in the mean time, and the check
is really very cheap
{ because it can/should be done after checking isNumber(): so
then we know we have an atomic and can use XLENGTH() }
The 0-length case I don't think we should change as I do find
NA (is logical!) to be an appropriate logical answer.
Martin Maechler
ETH Zurich and R Core team.
> Cheers Joris
> --
> Joris Meys Statistical consultant
More information about the R-devel
mailing list