gpt4 book ai didi

r - 显示与特定类关联的方法

转载 作者:行者123 更新时间:2023-12-04 17:01:41 26 4
gpt4 key购买 nike

我想查看与某个对象类关联的所有方法的列表。例如。如果我看到某个模型拟合例程返回一个“foo”类的对象,我想知道包(或任何其他包)是否定义了诸如 simulate.foo 之类的方法。 , update.foo , coef.foo , print.foo等等 我该怎么做?

我知道methods解决了逆问题(假设是 S3 类),但显然我不想搜索定义了 print 的每个对象。函数以找出我感兴趣的类(class)是否有一个。我可能在这里忘记了一些非常简单的事情。谢谢!

(理想情况下,很高兴看到 S3 和 S4 类的解决方案)。

更新 :理想情况下,解决方案应该显示隐藏的方法,就像 methods 一样功能确实。例如,methods("simulate")显示:

> methods("simulate")
[1] simulate.lm*

所以在查询与 lm 相关的方法时类,我们想要恢复这个模拟方法。

最佳答案

我是笨蛋,还是methods(class="foo")你想要什么(对于 S3 方法)???

methods(class="lm")
## [1] add1.lm* alias.lm* anova.lm case.names.lm*
## [5] confint.lm* cooks.distance.lm* deviance.lm* dfbeta.lm*
## [9] dfbetas.lm* drop1.lm* dummy.coef.lm* effects.lm*
## [13] extractAIC.lm* family.lm* formula.lm* hatvalues.lm
## [17] influence.lm* kappa.lm labels.lm* logLik.lm*
## [21] model.frame.lm model.matrix.lm nobs.lm* plot.lm
## [25] predict.lm print.lm proj.lm* qr.lm*
## [29] residuals.lm rstandard.lm rstudent.lm simulate.lm*
## [33] summary.lm variable.names.lm* vcov.lm*
##
## Non-visible functions are asterisked
showMethods适用于 S4 类(class)(取自 @JoshO'Brien 现已删除的答案,供引用):
library(sp)
showMethods(classes="SpatialPolygons")

## Function: [ (package base)
## x="SpatialPolygons"
##
## Function: addAttrToGeom (package sp)
## x="SpatialPolygons", y="data.frame"
##
## Function: coerce (package methods)
## from="GridTopology", to="SpatialPolygons"
## from="SpatialGrid", to="SpatialPolygons"
## from="SpatialPixels", to="SpatialPolygons"
## from="SpatialPolygons", to="SpatialLines"
## from="SpatialPolygons", to="SpatialPolygonsDataFrame"
##
## Function: coordinates (package sp)
## obj="SpatialPolygons"
##
## Function: coordnames (package sp)
## x="SpatialPolygons"
##
## Function: coordnames<- (package sp)
## x="SpatialPolygons", value="character"
##
## Function: over (package sp)
## x="SpatialGrid", y="SpatialPolygons"
## x="SpatialPoints", y="SpatialPolygons"
## x="SpatialPolygons", y="SpatialGrid"
## x="SpatialPolygons", y="SpatialGridDataFrame"
## x="SpatialPolygons", y="SpatialPoints"
## x="SpatialPolygons", y="SpatialPointsDataFrame"
##
## Function: overlay (package sp)
## x="SpatialGridDataFrame", y="SpatialPolygons"
## x="SpatialGrid", y="SpatialPolygons"
## x="SpatialPointsDataFrame", y="SpatialPolygons"
## x="SpatialPoints", y="SpatialPolygons"
## x="SpatialPolygons", y="SpatialGrid"
## x="SpatialPolygons", y="SpatialPoints"
##
## Function: plot (package graphics)
## x="SpatialPolygons", y="missing"
##
## Function: polygons (package sp)
## obj="SpatialPolygons"
##
## Function: polygons<- (package sp)
## object="data.frame", value="SpatialPolygons"
##
## Function: recenter (package sp)
## obj="SpatialPolygons"
##
## Function: spChFIDs (package sp)
## obj="SpatialPolygons", x="character"
##
## Function: spsample (package sp)
## x="SpatialPolygons"

关于r - 显示与特定类关联的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16048949/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com