[Rd] Adding difftime objects to POSIXt objects

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Feb 22 00:10:46 CET 2007


This is known, and not easy to solve given the way dispatch works for 
binary operators.

The documentation was broken when Ops.difftime was introduced.  You have 
found the known fix ....

On Wed, 21 Feb 2007, Jeffrey Horner wrote:

> Jeffrey Horner wrote:
>> Hello,
>>
>> ?DateTimeClasses states that "one can add or subtract a number of
>> seconds or a 'difftime' object from a date-time object, but not add two
>> date-time objects."
>>
>> So, is the below expected behavior?
>>
>> > x <- Sys.time()
>> > x
>> [1] "2007-02-21 16:19:56 CST"
>> > x + as.difftime("1","%H")
>> [1] "2007-02-21 16:19:57 CST"
>> Warning message:
>> Incompatible methods ("+.POSIXt", "Ops.difftime") for "+"
>>
>> "+.POSIXt" does behave as expected, though:
>>
>> > "+.POSIXt"(x,as.difftime("1","%H"))
>> [1] "2007-02-21 17:19:56 CST"
>>
>> > R.version
>>                 _
>> platform       i686-pc-linux-gnu
>> arch           i686
>> os             linux-gnu
>> system         i686, linux-gnu
>> status         Under development (unstable)
>> major          2
>> minor          5.0
>> year           2007
>> month          01
>> day            07
>> svn rev        40398
>> language       R
>> version.string R version 2.5.0 Under development (unstable) (2007-01-07
>> r40398)
>
> Oops! I thought I ran this on the latest revision, but the same behavior
> is exhibited in r40774:
>
> > x <- Sys.time()
> > x
> [1] "2007-02-21 16:44:16 CST"
> > x + as.difftime("1","%H")
> [1] "2007-02-21 16:44:17 CST"
> Warning message:
> Incompatible methods ("+.POSIXt", "Ops.difftime") for "+"
> > R.version
>                _
> platform       i686-pc-linux-gnu
> arch           i686
> os             linux-gnu
> system         i686, linux-gnu
> status         Under development (unstable)
> major          2
> minor          5.0
> year           2007
> month          02
> day            21
> svn rev        40774
> language       R
> version.string R version 2.5.0 Under development (unstable) (2007-02-21
> r40774)
>
>
> Jeff
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list