[R] Class for time of day?

Gabor Grothendieck ggrothendieck at gmail.com
Fri May 22 20:12:30 CEST 2009


On Fri, May 22, 2009 at 1:55 PM, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
> On Fri, May 22, 2009 at 12:28 PM, Gabor Grothendieck
> <ggrothendieck at gmail.com> wrote:
>
>> ...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
>
> Um, yes, I suppose that was the attitude in the 60's and 70's, but I think
> we have moved on from there.  cf.
> http://en.wikipedia.org/wiki/Data_abstraction
>
>>
>> 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.
>
> (18/24 day)/(1/24 day) is the perfectly meaningful dimensionless number 18,
> so this code should not break with a correct implementation of '/'.  (cf.
> http://en.wikipedia.org/wiki/Dimensional_analysis).  Alas, chron gives the
> nonsense result of 18 days.

Your point was that otherwise undefined operations should produce an
error and I was illustrating why that could not be introduced at this stage.
I had already suggested that you implement division if you found it important
and that was not the source of any disagreement.




More information about the R-help mailing list