Skip to content
Prev 21192 / 63424 Next

Ops.Date: promote characters to Dates?

On Sun, 25 Jun 2006, Ben Bolker wrote:

            
This is as documented (White Book p.473, referenced on the help page for 
'Ops').  [Surely part of the homework that the posting guide asks for.]

I have recently been expanding the help pages for group generics (and 
trying to remove some of the confusion caused by adding S4 group generics 
to the page for S3 group generics).  This now says (about S3 group 
generics only)

         2.  Group '"Ops"':

            *  '"+"', '"-"', '"*"', '"/"', '"^"', '"%%"', '"%/%"'

            *  '"&"', '"|"', '"!"'

            *  '"=="', '"!="', '"<"', '"<="', '">="', '">"'

         The classes of both arguments are considered in dispatching.
         If a method is found for just one or the same method is found
         for both, it is used.  If different methods are found, there is
         a warning about 'incompatible methods': in that case or if no
         method is found for either argument the default method is used.
Eh?  nchar is non-zero for almost all objects to be passed through here, 
including any coercible to Date.  (Remember nchar will itself coerce to 
character.)  And nchar(e1) will be a vector, not a scalar: perhaps 
is.character(e1) was what was intended?


I believe the issue is more general: naive users (those who confuse an 
object with its printed representation) expect to be able to compare 
classed objects to character strings, and for the classed objects to be 
converted by as.character() when doing so.  That is not what is done: 
coerceVector(x, STRSXP) is used internally.  At some point we need to 
consider changing that, but it is not easy as method dispatch depends on 
the environment, something that is often not known when coerceVector is 
invoked.
That it would not do so is further evidence of the good reasons for not 
providing such a method for people to misinterpret.  (It would be the 
number of days since 1970-01-01, but probably one would want to take 
floor() of a number here.)
Depends who is doing the expecting ....