[R] Class for time of day?

Gabor Grothendieck ggrothendieck at gmail.com
Fri May 22 18:28:42 CEST 2009


On Fri, May 22, 2009 at 11:01 AM, Stavros Macrakis
<macrakis at alum.mit.edu> wrote:
> On Fri, May 22, 2009 at 10:03 AM, Gabor Grothendieck
> <ggrothendieck at gmail.com> wrote:
>>
>> Regarding division you could contribute that to the chron package.
>> I've contributed a few missing items and they were incorporated.
>
> Good to know.  Maybe I'll do that....
>
>>
>> Giving an error when it does not understand something would be
>> dangerous as it could break much existing code so that would
>> probably not be possible at this stage.
>
> But would it break any existing *correct* code?  I find it hard to imagine
> any cases where adding 1 hour of difftime to times("12:00:00") should return
> 1.5 days rather than 13:00:00.
>
>>
>> The idea of defaulting to internal representations is based on
>> the idea that you get many features for free since the way the
>> internal representations work gives the right answer in many
>> cases.
>
> I must admit I am rather shocked by this approach.  Getting something "for
> free" is a bad bargain if what you get is nonsense.
>
>>
>> Its best to stick with the implicit philosophy that
>> underlies a package.  If you want a different philosophy then
>> its really tantamount to creating a new package.  I don't
>> think that one is right and the other wrong but simply
>> represent different viewpoints.
>
> So you would defend the "viewpoint" that 1 hour is the same thing as 1 day?

The way this might appear in code is if someone wanted to calculate the
number of one hour intervals in 18 hours.  One could write:

t18 <- times("18:00:00")
t1 <- times("1:00:00")
as.numeric(t18) / as.numeric(t1)

but since we all know that it uses internal representations unless it
indicates otherwise a typical code snippet might shorten it to:

as.numeric(t18 / t1)

and all such code would break if one were to cause that to generate an error.
(I think it would be ok if it generated a numeric automatically and that was
the enhancement I had suggested to you.)

You can try to argue that the user should not code that way but a huge
amount of chron code exists by now (note that chron may pre-date R).
If it were a new package one could consider raising new errors but at this
point in time it would be unwise.




More information about the R-help mailing list