我正在尝试为我创建的对象定义"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)
问题是我无法定义...的类,以便正确完成调度.任何的想法?
在阐述@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)
| 归档时间: |
|
| 查看次数: |
174 次 |
| 最近记录: |