Re: [Rd] Overwrite S3 methond from base package

From: Thaler,Thorn,LAUSANNE,Applied Mathematics <Thorn.Thaler_at_rdls.nestle.com>
Date: Tue, 14 Feb 2012 08:12:42 +0100

> In regard to "should", I think it is a
> very very bad idea.
>
> The result that someone gets depends on
> whether or not the new package is attached
> in the session. That is a recipe for hours
> (or days) of trying to figure out mysterious
> behavior.

I fully agree. However, there are 2 reasons in this particular case, why I decided nevertheless to be "evil":

  1. The package will never (well, never say never, but from today's point of view I see no reason, why this should ever happen) be published and is intended for internal use only.
  2. Even more important: I think that 'droplevels' in the base package has a major flaw as it silently drops any contrast chosen by the user. Hence, a user who wants to use droplevels, has to reassign all contrasts afterwards. In another discussion it was pointed out, that contrasts which worked fine for a factor, may be erroneous once a level is dropped (in the case we specify the contrasts matrix directly). I acknowledge this case (and so does my function as it falls back to the base version but issues a warning), yet I think for all the other cases, where the contrast is defined via a function, it would be the better behaviour to use the same contrast function rather than dropping it silently. As a consequence, I think that my function does no harm, for it does exactly the same as the base function while adding more functionality. Thus, even if the user is used to the annoying behaviour of base::droplevels and reassigns the contrast after each use of droplevels, he will see no difference whether or not my package is loaded. In the former case the step is however not necessary.

For the "how" part, I find out that I have to explicitly export my functions such that they can override the ones from the base package. Thus the solution was to add

export(droplevels.factor, droplevels.data.frame)

to my NAMESPACE file.

Thanks for your input,

-Thorn



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 14 Feb 2012 - 07:16:26 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 14 Feb 2012 - 16:40:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive