My question is how to apply the generic function plot()
using my new method for my inherited S4 class.
I extend the existing S4 class (whose name is stanfit) in rstan, say lowerS4class
, and define a new method for generic function plot
for the extended (inherited) S4 class, say upperS4class
.
But the following undesired selection (i.e. the selected method is the method
for the lower S4 class) occur with the following Note
in the R console when I apply the generic function plot()
for the extended S4 class object x
as plot(x)
.
Note: method with signature "lowerS4class#missing" chosen for function ‘plot’,
target signature "upperS4clss#missing".
"upperS4clss#ANY" would also be valid
Edit for comment-----------------------------------------
Inheritance
setMethod("plot",
signature(x = "upperS4class"),
definition = function(x){
foo(x)
}
)
where foo
is a function defined for upperS4class.
Def. for upperS4class
upperS4class <- setClass(
#Name for upper class
"upperS4class",
# Inheritance
contains = "lowerS4class"
# New slots
representation(
.....
),
# Initial values for new slots
prototype(
.....
),
)
---Edit for comments------------------
By changing the above as follows, it goes well. Thank you for @JDL.
setMethod("plot",
signature(x = "stanfitExtended",
y = "missing" # <--------------What's New !!
),
definition = function(x){
foo(x)
}
)