我怀疑在全局环境中会找到许多通用方法,它们更有可能在package的环境中。
修改帮助中的示例?Filter
(其中列出了基本包环境中的所有功能)如下我们可以使用过滤isGeneric
:
Filter(isGeneric,ls(all.names=TRUE, env = baseenv()))
## [1] "-" "!=" "$" "$<-" "%%" "%/%" "&" "*"
## [9] "/" "[" "[[" "[[<-" "[<-" "^" "|" "+"
## [17] "<" "<=" "==" ">" ">=" "abs" "acos" "acosh"
## [25] "all" "any" "anyDuplicated" "as.character" "as.data.frame" "as.difftime" "as.double" "as.numeric"
## [33] "as.real" "asin" "asinh" "atan" "atanh" "body<-" "c" "ceiling"
## [41] "close" "cos" "cosh" "cummax" "cummin" "cumprod" "cumsum" "digamma"
## [49] "dim" "dim<-" "duplicated" "exp" "expm1" "floor" "format" "gamma"
## [57] "intersect" "kronecker" "length" "lgamma" "log" "log10" "log1p" "log2"
## [65] "max" "min" "names" "print" "prod" "range" "rep" "rev"
## [73] "round" "setdiff" "sign" "signif" "sin" "sinh" "sort" "sqrt"
## [81] "sum" "summary" "tan" "tanh" "trigamma" "trunc" "union" "unique"
如果您需要查找函数来自哪个包,请使用:
find('function')
根据您的评论:要在搜索路径上搜索所有包以查找通用函数,请使用以下命令:
Filter(length,sapply(search(), function(x) {
Filter(isGeneric,ls(all.names=TRUE,env = as.environment(x)))
} ))
请注意,这包含在另一个Filter
语句中(以删除 where 元素 length==0
)。
.knownS3Generics
包环境中的内部对象base
也很有用。