[Rd] difftime arithmetic (PR#2345)

B.Rowlingson@lancaster.ac.uk B.Rowlingson@lancaster.ac.uk
Wed Dec 4 17:59:06 2002


Full_Name: Barry Rowlingson
Version: 1.6.0
OS: RH8 i386
Submission from: (NULL) (148.88.136.205)


Strange things happen if I premultiply a difftime() object with a number.

Example:

> d1 <- difftime(Sys.time(),Sys.time())
> d2 <- 1 * difftime(Sys.time(),Sys.time())
> d3 <- difftime(Sys.time(),Sys.time()) * 1

> d1
Time difference of 0 secs
 
  - thats fine

> d2
[1] 0
attr(,"units")
[1] "secs"
attr(,"class")
[1] "difftime"

 - d2 prints out with print.default, although it is of class(difftime)!
print.difftime isnt being called, even though:

> class(d2)
[1] "difftime"

> d3
Time difference of 0 secs

 - d3 prints out fine.

But if I dput those three objects, the files look identical, and when dgetted
(dgot?) they all act the same.

But if instead I save() them and then load() them then d2 acts weird again.

 More weirdness:

> unclass(d1)
[1] 0
attr(,"units")
[1] "secs"
 
 - as expected, but:

> unclass(d2)
[1] 0
attr(,"units")
[1] "secs"
attr(,"class")
[1] "difftime"

 similarly for unclass(unclass(unclass(d2))) !

 Any ideas?

Barry Rowlingson
Lancaster University
Lancaster, UK