/ Wishlist-for-R Public
ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1 #48
annoyance code robustess enhancement help wanted on bugs.r-project.org on r-devel or r-pkg-devel mailing lists
Issue has been raised on the R-devel or R-pkg-devel mailing lists
updated in R 3.6.0 (2019-04-26)
updated in R 4.2.0 (2022-04-22)
Updated in R-devel (to become R 4.3.0)
In the spirit of Issue #38 (
if/while (c(TRUE, TRUE)) ...) of giving a warning (soon error), @hadley proposed in a Tweet:
Today we have that
x || yperforms
x || yfor
length(x) > 1. For instance,
This property is symmetric in LHS and RHS (i.e.
y || xbehaves the same) and it also applies to
x && y.
The issue is that the above truncation of
xis completely silent -there's neither an error nor a warning being produced.
x || yand
x && ywith a non-scalar
yis likely a mistake. Either the code is written assuming
yare scalars, or there is a coding error and vectorized versions
x | yand
x & ywere intended. Should
x || yalways be considered an mistake if
length(x) != 1or
length(y) != 1? If so, should it be a warning or an error? For instance,
What about the case where
length(x) == 0or
length(y) == 0? Today
x || yreturns
NAin such cases, e.g.
I don't know the background for this behavior, but I'm sure there is an argument behind that one. Maybe it's simply that
&&should always return a scalar logical and neither
FALSEcan be returned.
The text was updated successfully, but these errors were encountered: