Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic functions and reference classes in R

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?

like image 848
tchakravarty Avatar asked Aug 14 '26 10:08

tchakravarty


2 Answers

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" 
like image 93
Scott Ritchie Avatar answered Aug 16 '26 06:08

Scott Ritchie


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.

like image 35
IRTFM Avatar answered Aug 16 '26 07:08

IRTFM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!