[Rd] Monkey patching +.POSIXt
Hadley Wickham
hadley at rice.edu
Wed Sep 9 16:40:35 CEST 2009
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/
More information about the R-devel
mailing list