s4 - setMethod for two different object signature in R -
how make using 1 setmethod function section same in following 2 line codes? signature("triangle|square"). thank you.
setmethod("sides", signature("triangle"), function(object) 3) setmethod("sides", signature("square"), function(object) 3)
the usual approach is
.sides_body = function(object) 3 setmethod("sides", "triangle", .sides_body) setmethod("sides", "square", .sides_body)
unless there class relationship , definition same across 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)
Comments
Post a Comment