From hadley at rice.edu  Wed Sep  9 16:40:35 2009
From: hadley at rice.edu (Hadley Wickham)
Date: Wed, 9 Sep 2009 09:40:35 -0500
Subject: [Rd] Monkey patching +.POSIXt
Message-ID: <f8e6ff050909090740l16ee7dbanf3eb9a3b2ad43985@mail.gmail.com>

Hi all,

This summer I've been working with a grad student to bring more of the
date time classes from JODA (http://joda-time.sourceforge.net/) into
R. To make these work seamlessly with existing date time objects, we
need to patch +.POSIXt. (The ruby community uses the term
monkey-patching for this sort of ill-advised, by sometimes necessary,
internal hackery, hence the title.) The problem is I can't figure out
how to override +.POSIXt so that it gets called from +.  Simply
including a new +.POSIXt function in the package doesn't work because
(I presume) + finds and uses base::+.POSIXt. The next thing I tried
was

assignInNamespace("+.POSIXt", lubridate::`+.POSIXt`, "base")

but that doesn't seem to work either, despite the documentation: "They
do attempt to alter a copy registered as an S3 method if one is
found."  (perhaps there is a missing not there?)

In desperation, I also tried the following internal, undocumented
function, but it didn't help either:

registerS3method("+", "POSIXt", lubridate::`+.POSIXt`)

Any ideas?

Thanks,

Hadley

-- 
http://had.co.nz/



[Rd] Monkey patching +.POSIXt
Hadley Wickham