Re: [Rd] Overwrite S3 methond from base package

From: Patrick Burns <pburns_at_pburns.seanet.com>
Date: Mon, 13 Feb 2012 17:18:09 +0000

The key question is:

 > So, is there any way to overwrite droplevels.factor and  > droplevels.data.frame from the base package with my functions?

There is "can" and there is "should".

I don't know the answer to "can".

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.

Much better, I think, is to create a new generic.

Pat

On 13/02/2012 11:59, Thaler,Thorn,LAUSANNE,Applied Mathematics wrote:
> Dear all,
>
> I am developing a package, which bundles my most frequently used
> functions. One of those is a modified version of droplevels from the
> base package (basically, it preserves any contrast function which was
> used to create the factor, contrast matrices are not kept, for they
> could be wrong if a level is dropped).
>
> In my NAMESPACE file I've the following directives, which should export
> my methods:
>
> S3method(droplevels, factor)
> S3method(droplevels, data.frame)
>
> However, when I load my package and I try to use those functions, the
> dispatching mechanism calls the functions droplevels.factor and
> droplevels.data.frame from the _base package_.
>
> So, is there any way to overwrite droplevels.factor and
> droplevels.data.frame from the base package with my functions? Or do I
> have to create a generic function on my own?
>
> Thanks for your help.
>
> Kind Regards,
>
> Thorn
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Patrick Burns
pburns_at_pburns.seanet.com
twitter: @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Mon 13 Feb 2012 - 17:22:45 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 - 08:40:17 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