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

From: Wacek Kusnierczyk <>
Date: Tue, 24 Feb 2009 10:13:22 +0100

Martin Maechler wrote:
> >> 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 )

point taken.

> 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


> 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.

not quite sure what you mean by 'closeness to mathematical notation' here.

> 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.
> '<'(1)
> it basically does [empty] < 1 and hence returns the same as
> NULL < 1
which is consistent with NULL + 1. btw:

  1. you might want to keep the error message from applying < and other relops to an inappropriate number of arguments in sync with the message one gets from, e.g., '+'(1,2,3). (you may want to actually update the message from '+' and relatives, as it seems that there are more operators that give an error message similar to that of '<'. the attached patch fixes this; it has been compiled and successfully tested -- see below.)
  2. '+'() and '+'(1,2,3) say the operator needs one or two arguments, but again, '+' is documented as a *binary* operator. i guess the intention here is to have them unary or binary, and it's the docs that should be updated.


The patch for src/main/arithmetic.c was prepared as follows:

svn co cd trunk
# modifications made to src/main/character.c svn diff > do_grep.diff

The patched sources were successfully compiled and tested as follows:

svn revert -R .
patch -p0 < do_grep.diff
make check mailing list
Received on Tue 24 Feb 2009 - 08:17:51 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 - 09: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