简体   繁体   中英

Using R, how to delist a function from a methods namespace such as `S3`?

The plot functions in R are tied to an S3method . By default,

> methods("plot")
 [1] plot.acf*           plot.data.frame*    plot.decomposed.ts* plot.default       
 [5] plot.dendrogram*    plot.density*       plot.ecdf           plot.factor*       
 [9] plot.formula*       plot.function       plot.hclust*        plot.histogram*    
[13] plot.HoltWinters*   plot.isoreg*        plot.lm*            plot.medpolish*    
[17] plot.mlm*           plot.ppr*           plot.prcomp*        plot.princomp*     
[21] plot.profile.nls*   plot.raster*        plot.spec*          plot.stepfun       
[25] plot.stl*           plot.table*         plot.ts             plot.tskernel*     
[29] plot.TukeyHSD*     


I can manually define a new function at the console:

plot.tukey = function(x) {}

It automatically gets listed in the methods("plot") based on its naming convention:

> methods("plot")
 [1] plot.acf*           plot.data.frame*    plot.decomposed.ts* plot.default       
 [5] plot.dendrogram*    plot.density*       plot.ecdf           plot.factor*       
 [9] plot.formula*       plot.function       plot.hclust*        plot.histogram*    
[13] plot.HoltWinters*   plot.isoreg*        plot.lm*            plot.medpolish*    
[17] plot.mlm*           plot.ppr*           plot.prcomp*        plot.princomp*     
[21] plot.profile.nls*   plot.raster*        plot.spec*          plot.stepfun       
[25] plot.stl*           plot.table*         plot.ts             plot.tskernel*     
[29] plot.tukey          plot.TukeyHSD*     
see '?methods' for accessing help and source code

How do I delist or unregister the function from the default S3 namespace?

That is, I want plot.tukey to be declared a function, but not be attached to the S3 namespace. Is there an unUseMethod functionality?

It seems like you are wrestling deep in the bowels of R and your motivation is a desire to define

plot.tukey = function(x) {}

which would show up on a methods("plot") call rather than say

plot_tukey = function(x) {}

which would not?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM