简体   繁体   English

使用 R,如何从诸如“S3”之类的方法命名空间中删除 function?

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

The plot functions in R are tied to an S3method . R 中的plot函数与 S3method 相关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:我可以在控制台手动定义一个新的 function :

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?如何从默认S3命名空间中删除或unregister delist

That is, I want plot.tukey to be declared a function, but not be attached to the S3 namespace.也就是说,我希望将 plot.tukey 声明为 function,但不附加到S3命名空间。 Is there an unUseMethod functionality?是否有unUseMethod功能?

It seems like you are wrestling deep in the bowels of R and your motivation is a desire to define看起来你在 R 的内心深处挣扎,你的动机是想要定义

plot.tukey = function(x) {}

which would show up on a methods("plot") call rather than say这将出现在methods("plot")调用而不是说

plot_tukey = function(x) {}

which would not?哪个不会?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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