Re: [Rd] [R] are arithmetic comparison operators binary?

From: Martin Maechler <>
Date: Tue, 24 Feb 2009 09:06:54 +0100

>>>>> "WK" == Wacek Kusnierczyk <> >>>>> on Mon, 23 Feb 2009 19:29:31 +0100 writes:

    WK> Martin Maechler wrote:
    >>>>>>> "WK" == Wacek Kusnierczyk <>
    >>>>>>> on Mon, 23 Feb 2009 12:06:32 +0100 writes:

>> Thank you, Wacek,
>> though .. "wrong mailing list"

    WK> apologies. i was actually asking for explanation, assuming that it     WK> might be my misunderstanding, rather than reporting a bug.

( yes; but it is really a technical topic, also touching on   extending R [below], hence --> R-devel )

    WK> the man page for relational operators (see, e.g., ?'<') says:
    WK> "
    WK> Binary operators which allow the comparison of values in atomic vectors.


    WK> Arguments:
    WK> x, y: atomic vectors, symbols, calls, or other objects for which
    WK> methods have been written.
    WK> "


    WK> it is somewhat surprizing that the following works:

    WK> '<'(1)
    WK> # logical(0)

    WK> '<'()
    WK> # logical(0)

    WK> '<'(1,2,3)
    WK> # TRUE
>> a bit surprising (sic!), indeed, even for me.
>> Thanks for your notice and report!

    WK> you're welcome.

    WK> shouldn't the tests have captured it? i think you should have a check     WK> for every feature following from the docs.

yes, we should.

  >> R is free software and comes with ABSOLUTELY NO WARRANTY.
  >> You are welcome to ......................
  >>   .............

  >> R is a collaborative project with many contributors.

I think we'd gladly accept well-written & commented extra   <R-x.y.z>/tests/foo.R
files or patches to existing ./tests/*.R particularly if the contributor shows the new tests are systematically covering currently untested areas... Again: this really belongs to R-devel

--> I'm CCing there {and write a quick reply on R-help about

    the mailing list redirection}

    WK> plus those undocumented, but assumed by the developers.

  ;-) :-)

Indeed, we are also grateful for (concise!) patches to man/*.Rd help files.

>> If you'd looked a bit in the sources, you'd seen that they
>> really are supposed to be binary only.

    WK> it wouldn't be nonsensical to let them be of arbitrary arity (in a     WK> well-documented manner), though it might confuse users.

Yes (to the latter). One of the beauties of S and R is the syntax closeness to mathematical notation. Many of us know that Lisp has beauties that S can never have, but that's really in different beauty-space.

>> A very small change in the sources does accomplish this, passes
>> the standard checks (and I cannot imagine reasonable code that
>> would have relied on the more lenient behavior), so
>> this will have changed in one of the next versions of R-devel.

    WK> thanks.

    WK> just a question (i haven't checked the sources, maybe i should):  what
    WK> is it that happens when one of the operators is called with n = 0 or 1
    WK> argument?  how does it come up with logical(0) rather than NA?

In some of the cases e.g.


it basically does [empty] < 1 and hence returns the same as

   NULL < 1

Martin Maechler, ETH Zurich mailing list Received on Tue 24 Feb 2009 - 07:10:36 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 24 Feb 2009 - 08:30:42 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive