1

我的问题是如何plot()使用我继承的 S4 类的新方法应用通用函数。

我扩展了rstan中现有的 S4 类(其名称为stanfit),比如说,并为扩展的(继承的)S4 类定义了一个新的泛型函数方法,比如说。lowerS4classplotupperS4class

但是,当我将扩展 S4 类对象Note的通用函数应用为.plot()xplot(x)

Note: method with signature "lowerS4class#missing" chosen for function ‘plot’,
 target signature "upperS4clss#missing".
 "upperS4clss#ANY" would also be valid

编辑评论-----------------------------------------------------

遗产

  setMethod("plot",
           signature(x = "upperS4class"),
           definition = function(x){   
             foo(x)
             }

           )

其中foo是为 upperS4class 定义的函数。

定义。为了upperS4class

upperS4class <- setClass(
                  #Name for upper class
                  "upperS4class",

                   # Inheritance
                   contains = "lowerS4class"

                   # New slots
                   representation(

                      .....
                   ),

                   # Initial values for new slots
                   prototype(
                      .....


                      ),

)

---编辑评论-------

通过如下更改上述内容,一切顺利。谢谢@JDL。

 setMethod("plot",
           signature(x = "stanfitExtended",
                     y = "missing"       # <--------------What's New !!
                     ),
           definition = function(x){ 
             foo(x)
             }

       )
4

0 回答 0