[R] Another R syntax question

Richard A. O'Keefe ok at cs.otago.ac.nz
Wed Sep 3 08:08:28 CEST 2003


The file src/library/base/R/print.R
contains this line:

    x0 <- xm[okP]==0 != (as.numeric(Cf[okP])==0)

I didn't know R allowed that, and I wonder if it is deliberate?
                                        
In mathematics, you would expect x = y not= z to mean
(x = y) and (y not= z).;
In R, it is parsed as (x == y) != z.

While I have to admit that the spacing around == and != in print.R's
example does actually convey the actual association, in a vaguely
Principia Mathematica-ish way, I have to wonder:

Is R really seriously intended to swallow x == y != z without complaint?

If the line

%left       GT GE LT LE EQ NE

in src/main/gram.y were changed to

%nonassoc   GT GE LT LE EQ NE

then the line

    x0 <- xm[okP]==0 != (as.numeric(Cf[okP])==0)

in src/library/base/R/print.R would have to be changed to

    x0 <- (xm[okP]==0) != (as.numeric(Cf[okP])==0)

and all things considered, surely that would be an improvement?




More information about the R-help mailing list