用3个点定义S4方法

Roc*_*nce 4 r dispatch s4

我正在尝试为我创建的对象定义"c"方法.

就像是

setMethod("c", 
          signature(...), 
          definition=function (...) {
            myObject = list(...)[[1]]
            myObject@mySlot=lapply(list(...), FUN = function(x) slot(x, "mySlot"))
            return(myObject)
         }
)
Run Code Online (Sandbox Code Playgroud)

问题是我无法定义...的类,以便正确完成调度.任何的想法?

Mar*_*gan 5

在阐述@hadley的评论时,签名应该适用于您的班级,并且应该遵循定义getGeneric.于是

> getGeneric("c")
standardGeneric for "c" defined from package "base"

function (x, ..., recursive = FALSE)
standardGeneric("c", .Primitive("c"))
<environment: 0x4956ab8>
Methods may be defined for arguments: x, recursive
Use  showMethods("c")  for currently available ones.
Run Code Online (Sandbox Code Playgroud)

所以

setClass("A", representation(x="numeric"))
setMethod("c", "A", function(x, ..., recursive=FALSE) {
  "here I am"
})
Run Code Online (Sandbox Code Playgroud)

> c(new("A"), new("A"))
[1] "here I am"
Run Code Online (Sandbox Code Playgroud)