Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 用3个点定义S4方法_R_Dispatch_S4 - Fatal编程技术网

R 用3个点定义S4方法

R 用3个点定义S4方法,r,dispatch,s4,R,Dispatch,S4,我正在尝试为我创建的对象定义“c”方法 差不多 setMethod("c", signature(...), definition=function (...) { myObject = list(...)[[1]] myObject@mySlot=lapply(list(...), FUN = function(x) slot(x, "mySlot")) return(myObj

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

差不多

setMethod("c", 
          signature(...), 
          definition=function (...) {
            myObject = list(...)[[1]]
            myObject@mySlot=lapply(list(...), FUN = function(x) slot(x, "mySlot"))
            return(myObject)
         }
)
问题是我无法定义。。。以便正确地进行调度。
有什么想法吗?

详细说明@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.

查看
getGeneric(“c”)
——您在
x
上定义方法,而不是
setClass("A", representation(x="numeric"))
setMethod("c", "A", function(x, ..., recursive=FALSE) {
  "here I am"
})
> c(new("A"), new("A"))
[1] "here I am"