[R] New methods for generic functions show and print : some visible with ls(), some not

Duncan Murdoch murdoch at stats.uwo.ca
Sun Feb 28 01:23:41 CET 2010


On 27/02/2010 6:15 PM, Joris Meys wrote:
> Thank you both for your answers.
> 
> On Fri, Feb 26, 2010 at 7:58 PM, Duncan Murdoch <murdoch at stats.uwo.ca>wrote:
> 
>> You aren't seeing the print method, you are seeing a newly created print
>> generic function.  As Uwe mentioned, print() is not an S4 generic, so when
>> you create your print method, a new S4 generic also gets created.  You
>> should be using show(), which will be called by print() when necessary.
>>
>> When you say "clear the memory", I'm not sure what you have in mind, but S4
>> methods are not stored in your workspace, so rm(list=ls()) won't delete
>> them.  You need removeMethod() to get rid of a method.
>>
>> Duncan Murdoch
>>
> 
> What I meant with "clear the memory" is exactly rm(list=ls()). I use the
> same analysis on different rather big datasets, so I have to make some space
> once in a while. To lose the "print" generic (thx for the correction) every
> time I considered highly inconvenient. I'll use the show method, thank you
> both for the tip.
> 
> Do I understand it right that every generic I define in a normal scriptfile
> is saved in the workspace, and thus can be removed with rm() ?

I think so if you do it in the normal way.  It's possible to create them 
elsewhere, so "every generic" might not mean every generic.

Duncan Murdoch



More information about the R-help mailing list