[Rd] Historical NA question
Duncan Murdoch
murdoch.duncan at gmail.com
Tue May 6 19:14:55 CEST 2014
On 06/05/2014 1:01 PM, peter dalgaard wrote:
> On 06 May 2014, at 18:20 , Hadley Wickham <h.wickham at gmail.com> wrote:
>
> >>> BTW, that %in% has precedence over arithmetic operations is surprising,
> >>> error-prone, and doesn't cover any reasonable use case (who needs to
> >>> multiply the logical vector returned by %in% by some value?) but that's
> >>> another story:
> >>
> >> The point here is that the %foo% operators all have the _same_ precedence. In principle, they can be user-coded, and there is no way to express what precedence is desirable. It may turn out slightly weird for %in%, but think of what would happen if %*% had lower precedence than addition.
> >
> > This is getting way off topic, but I find the precedence of ! to be
> > more surprising:
> >
> >> !F + !F
> > [1] FALSE
> >
> > i.e. that's interpreted as !(F + !F) not (!F) + (!F).
>
> Yes, UNOT has lower precedence than arithmetic and comparison ops in gram.y. So
>
> > !2<3
> [1] FALSE
> > !2+2==4
> [1] FALSE
>
> I suspect that that is as old as original sin (i.e., inherited from S). Anyone have the Blue Book to hand to verify? It's easy enough to change, but the sky would likely fall down on our heads if we tried...
These are the differences between what ?Syntax says and the blue book:
::, :::, @, unary +, ~, ->>, =, ? are not mentioned in the blue book.
& && | and || all have the same precedence in the blue book, but & and
&& are higher precedence in R.
The other assignment operators are ordered as <<-, ->, (<-, _) in the
blue book (where parens indicate equal precedence), but in R they are
(->, ->>), (<-, <<-), =.
>
> Also surprising:
>
> > quote(!2+!2)
> !2 + (!2)
>
> where it is somewhat perplexing what the parentheses are supposed to be good for.
That looks like a deparsing bug.
Duncan Murdoch
More information about the R-devel
mailing list