我正在阅读Martin Morgan's notes on reference classes,在幻灯片7中,他使用setMethod
来定义show
函数,而不使用setGeneric
将其设置为通用。
为什么允许这样做?是否存在所有引用类声明为通用的方法列表,包括show
?
答案 0 :(得分:5)
show
已经是一个通用函数:
> isGeneric("show")
[1] TRUE
通过调用getGenerics
:
> getGenerics()
An object of class "ObjectsWithPackage":
Object: "-" "!=" "[" "*" "/" "&" "%/%" "%%" "^" "+"
Package: "base" "base" "base" "base" "base" "base" "base" "base" "base" "base"
Object: "<" "<=" "==" ">" ">=" "|" "$" "$<-" "abs" "acos"
Package: "base" "base" "base" "base" "base" "base" "base" "base" "base" "base"
Object: "acosh" "addNextMethod" "Arith" "asin" "asinh" "atan" "atanh" "body<-"
Package: "base" "methods" "base" "base" "base" "base" "base" "base"
Object: "cbind2" "ceiling" "coerce" "coerce<-" "Compare" "Complex" "cos"
Package: "methods" "base" "methods" "methods" "methods" "base" "base"
Object: "cosh" "cummax" "cummin" "cumprod" "cumsum" "digamma" "exp" "expm1"
Package: "base" "base" "base" "base" "base" "base" "base" "base"
Object: "floor" "gamma" "initialize" "kronecker" "lgamma" "loadMethod" "log"
Package: "base" "base" "methods" "base" "base" "methods" "base"
Object: "log10" "log1p" "log2" "Logic" "Math" "Math2" "Ops" "rbind2"
Package: "base" "base" "base" "base" "base" "methods" "base" "methods"
Object: "round" "show" "sign" "signif" "sin" "sinh" "slotsFromS3" "sqrt"
Package: "base" "methods" "base" "base" "base" "base" "methods" "base"
Object: "Summary" "tan" "tanh" "trigamma" "trunc"
Package: "base" "base" "base" "base" "base"
答案 1 :(得分:1)
如果查看?show
,您会看到showDefault
有默认发送。我似乎记得看到一系列其他可用的方法,但我现在找不到它们的链接,所以对于你的第二个问题,我不知道。