SetMethod for two different object signatures in R
1 answer
The usual approach
.sides_body = function(object) 3
setMethod("sides", "Triangle", .sides_body)
setMethod("sides", "Square", .sides_body)
if there is no class relationship and the definition is the same for all classes
setClass("Shape")
setClass("Triangle", contains="Shape")
setClass("Square", contains="Shape")
setClass("Circle", contains="Shape")
setMethod("sides", "Shape", function(boject) 3)
setMethod("sides", "Circle", function(object) Inf)
+4
source to share