Well, it originates in C, where & and | are bitwise operators. -pd
> On 5 Mar 2020, at 15:44 , Jeff Jetton <jeff.jet...@gmail.com> wrote: > > This is something that, by the way, I've always thought R got backwards. If > you want an operation to handle "one thing" against "one other thing" > (scalars), a single & or | seems like the obvious symbol for it. Whereas an > operation on "multiple things" (vectors) would be well-represented by a > multiple-character symbol like && or ||. > > But as long as I remember that it's backwards, I can keep them sorted out. > :-) > > - Jeff > > On Thu, Mar 5, 2020 at 6:14 AM Uwe Ligges <lig...@statistik.tu-dortmund.de> > wrote: > >> >> >> On 05.03.2020 09:45, Rolf Turner wrote: >>> >>> On 5/03/20 9:04 pm, Tomas Kalibera wrote: >>> >>>> On 3/5/20 4:26 AM, John Lawson wrote: >>>>> I see this error on the CRAN Check report >>> >>> <SNIP> >>> >>>>> Fatal error: the condition has length > 1 >>>> >>>> The problem is that the condition t1 == "I" & t2 == "(" of the if >>>> statement in the code is not a scalar. Even though this has been allowed >>>> in R historically, the first element has been used, it is almost always >>>> a sign of coding error, so it is going to become a runtime error. >>>> >>>> So what one should do is fix the code to only use scalar conditions - >>>> ensure t1, t2 are scalar, replace & by &&. >>> >>> Perhaps I'm being even thicker than usual (imagine that!) >> >> Oh dear, but this time it is true...: >> >> >>> but I don't >>> grok that last recommendation: "replace & by &&". It's usually >>> harmless but indicates a lack of understanding. The "&&" operator >>> evaluates the second condition only if the first condition is TRUE. It >> >> Right, and as the conditions are scalar, we never have to evaluate the >> 2nd if the first is FALSE unless you do it for side effects. >> >> So for logical operators on scalar logical vectors, one should prefer && >> and || for efficeincy reasons. >> >> Best, >> Uwe >> >> >> >> >>> is useful (only) in setting where the second condition is meaningful >>> only when the first condition is TRUE. >>> >>> Things like: >>> >>> if(!is.null(x) && x > 0) >>> >>> If "x" were null then the second condition would cause an error to be >>> thrown if you used "&" rather than "&&". >>> >>> In all (???) situations where "&&" works, then "&" works as well. >>> However it's a Good Idea to use the language as intended. >>> >>> It I'm missing some point here, please enlighten me. >>> >>> <SNIP> >>> >>> cheers, >>> >>> Rolf >>> >> >> ______________________________________________ >> R-package-devel@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-package-devel >> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-package-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-package-devel -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd....@cbs.dk Priv: pda...@gmail.com ______________________________________________ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel