Skip to content
Prev 37136 / 63421 Next

Defining a method that behaves like '$'?

On Jul 10, 2010, at 7:24 AM, Barry Rowlingson wrote:

            
Just to throw in another $0.02, in hindsight, not fully understanding the context of Renaud's original query, this may be a situation where implementing relevant extractor functions would make sense. 

Consider functions such as coef(), effects(), fitted() etc. for regression models. These allow you and your users to have functions that return components of your object class without being concerned about the internal structure of your object. Importantly, you and your users will not be affected by future changes to your object structure that you may find you have to implement over time. You simply modify the extractor functions as required when the internal structure of your class changes, so that they can be used post-change, without breaking existing code.

So for example:

  toto(a)

would return a at slot1[['toto']] and

  tata(a)

would return a at slot2[['tata']].

Food for thought.

Marc