From maechler at stat.math.ethz.ch  Tue Feb 24 09:06:54 2009
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Tue, 24 Feb 2009 09:06:54 +0100
Subject: [Rd] [R] are arithmetic comparison operators binary?
In-Reply-To: <49A2EB0B.5000409@idi.ntnu.no>
References: <49A28338.1080009@idi.ntnu.no>
	<18850.47461.374326.854888@stat.math.ethz.ch>
	<49A2EB0B.5000409@idi.ntnu.no>
Message-ID: <18851.43678.942938.967721@stat.math.ethz.ch>

>>>>> "WK" == Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk at idi.ntnu.no>
>>>>>     on Mon, 23 Feb 2009 19:29:31 +0100 writes:

    WK> Martin Maechler wrote:
    >>>>>>> "WK" == Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk at idi.ntnu.no>
    >>>>>>> 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. 
   '<'(1)   

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

   NULL < 1

Regards,
Martin Maechler, ETH Zurich



[Rd] [R] are arithmetic comparison operators binary?
Martin Maechler