Вопрос

I am reading Martin Morgan's notes on reference classes, and on slide 7, he uses setMethod to define the show function without setting it previously as a generic using setGeneric.

Why is this allowed? Is there a list of methods that are declared as generic for all reference classes, including show?

Это было полезно?

Решение

show is already a generic function:

> isGeneric("show")
[1] TRUE

A list of generics in your parent environment can be obtained by calling 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" 

Другие советы

If you look at ?show you see that there is a default dispatch to showDefault. I seem to remember seeing a list of other methods that were presumed available, but I cannot find the link to them at the moment, so to your second question, I do not know.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top