Skip to content

Creating methods

3 messages · Göran Broström, Ivan Krylov

#
I am reading Hadley's "Advanced R", Section 13.4.3 
(https://adv-r.hadley.nz/s3.html). It starts

----------------------------------------------------------------
There are two wrinkles to be aware of when you create a new method:

     First, you should only ever write a method if you own the generic 
or the class. R will allow you to define a method even if you don?t, but 
it is exceedingly bad manners. Instead, work with the author of either 
the generic or the class to add the method in their code.
----------------------------------------------------------------

I was stunned when I read it. I write methods all over the place for 
generics like print, summary, plot, etc.

So my question is: Do I "own" those generics, or am I just showing bad 
manners?

Thanks, G?ran
#
? Mon, 24 Apr 2023 15:07:50 +0200
G?ran Brostr?m <gb at ehar.se> ?????:
You most likely do that for your own classes. It's sufficient to own
either the generic or the class, though owning both wouldn't hurt.
#
Den 2023-04-24 kl. 15:14, skrev Ivan Krylov:
Thanks, I see. I define a class when I write a method, so no problem. 
What Hadley meant was that I shouldn't rewrite print.lm, for instance.

G?ran