From kevin.r.coombes at gmail.com  Tue Jul  9 13:14:31 2013
From: kevin.r.coombes at gmail.com (Kevin R. Coombes)
Date: Tue, 09 Jul 2013 06:14:31 -0500
Subject: [Rd] Is difftime a "class"
In-Reply-To: <CAHgH9_EJv97fGoiBZoS70MpdotrHwJrp6KJ4NrFXJg-WRjj_UA@mail.gmail.com>
References: <CAHgH9_EJv97fGoiBZoS70MpdotrHwJrp6KJ4NrFXJg-WRjj_UA@mail.gmail.com>
Message-ID: <51DBF097.2040804@gmail.com>

difftime is an S3 class, not an S4 class. To convert it, include the line

setOldClass("difftime")

and the setMethod call should work.

On 7/9/2013 6:03 AM, Dan Murphy wrote:
> I am trying to write S4 methods with "difftime" in the signature but
> am being "informed" (? not a warning or error) that "difftime" is not
> a class. Nevertheless, dispatch takes place. Should I simply ignore
> that "information"? Here is a toy example:
>
>> setClass("foo", contains = "Date")
>> setMethod("+", c("foo", "difftime"), function(e1, e2) callNextMethod())
> in method for ?+? with signature ?"foo","difftime"?: no definition for
> class ?difftime?
> [1] "+"
>> x<- new("foo", as.Date("2013-06-30"))
>> dt<- as.difftime(1, units = "days")
>> x + dt
> [1] "2013-07-01"
>
> Thank you,
> Dan Murphy
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Is difftime a "class"
Kevin R. Coombes