From Mark.Bravington at csiro.au  Thu Sep 10 03:19:39 2009
From: Mark.Bravington at csiro.au (Mark.Bravington at csiro.au)
Date: Thu, 10 Sep 2009 11:19:39 +1000
Subject: [Rd] Monkey patching +.POSIXt
In-Reply-To: <f8e6ff050909091742l4175eed3le4e070c88b04ff38@mail.gmail.com>
References: <f8e6ff050909090740l16ee7dbanf3eb9a3b2ad43985@mail.gmail.com>
	<62C82B39B8A85E4B95A18F7F7B852F87054BBBA246@exvic-mbx03.nexus.csiro.au>
	<f8e6ff050909091742l4175eed3le4e070c88b04ff38@mail.gmail.com>
Message-ID: <62C82B39B8A85E4B95A18F7F7B852F87054BBAD048@exvic-mbx03.nexus.csiro.au>

Hmmm... 'assign.to.base( "+.POSIXt", myfun)' works on my system (2.9.1 patched on Windows, at time of writing). Could be the 'mvbutils' version, I guess. What happened when you tried it? And what if you did 'getAnywhere( "+.POSIXt")' afterwards?

I was wrong about where '+.POSIXt' lives, though-- sorry. It is directly in 'baseenv()', not in 'baseenv().__S3MethodsTable__.'.  'assign.to.base' looks in both, and in other packages as well as 'baseenv()'.

Mark

-- 
Mark Bravington
CSIRO Mathematical & Information Sciences
Marine Laboratory
Castray Esplanade
Hobart 7001
TAS

ph (+61) 3 6232 5118
fax (+61) 3 6232 5012
mob (+61) 438 315 623

Hadley Wickham wrote:
>> In this particular case, the trick is to assign the new version both
>> into the namespace and into the environment '.__S3MethodsTable__.'
>> inside the namespace.  
> 
> The problem is +.POSIXt doesn't seem to be there:
> 
>> exists("+.POSIXt", asNamespace("base")$.__S3MethodsTable__.,
>> inherits=F)
> [1] FALSE
> 
> 
>> Speaking as a monkey, I do this kind of thing regularly, and there
>> is a function 'assign.to.base' in the 'mvbutils' package that does
>> it automatically, e.g.  
>> 
>> assign.to.base( '+.POSIXt', my.plus.POSIXt)
> 
> I tried that too, but without any luck.
> 
> Hadley


[Rd] Monkey patching +.POSIXt
Mark.Bravington at csiro.au