R S4初始化函数中的'.Object'和'object'有什么区别?
What's the difference between '.Object' and 'object' in R S4 initialize function?
I use S4 in R and what to define a initialize function. But .Object works well and object will failed. why?
############ method1: Bad
setMethod("initialize", "XY2Z", function(object,...){
object <- callNextMethod()
object@nodes <- getNodes(object)
object
})
########### method2: Good
setMethod("initialize", "XY2Z", function(.Object,...){
.Object <- callNextMethod()
.Object@nodes <- getNodes(.Object)
.Object
})
method1: Error in conformMethod(signature, mnames, fnames, f, fdef, definition) :
带'initialize'标记的'.Object="XY2Z"'的方法: 方法定义里所忽略的正式参数(.Object = "XY2Z", ... = "XY2Z")不能存在于标记
method2: work well
我不确定为什么只在一种情况下出现错误,但这里可能有一个解决方法
initialize <- function(object,...) 0
setGeneric("initialize")
# method 1 (doesn't give an error)
setMethod("initialize", "XY2Z", function(object,...){
object <- callNextMethod()
object@nodes <- getNodes(object)
object
})
I use S4 in R and what to define a initialize function. But .Object works well and object will failed. why?
############ method1: Bad
setMethod("initialize", "XY2Z", function(object,...){
object <- callNextMethod()
object@nodes <- getNodes(object)
object
})
########### method2: Good
setMethod("initialize", "XY2Z", function(.Object,...){
.Object <- callNextMethod()
.Object@nodes <- getNodes(.Object)
.Object
})
method1: Error in conformMethod(signature, mnames, fnames, f, fdef, definition) : 带'initialize'标记的'.Object="XY2Z"'的方法: 方法定义里所忽略的正式参数(.Object = "XY2Z", ... = "XY2Z")不能存在于标记
method2: work well
我不确定为什么只在一种情况下出现错误,但这里可能有一个解决方法
initialize <- function(object,...) 0
setGeneric("initialize")
# method 1 (doesn't give an error)
setMethod("initialize", "XY2Z", function(object,...){
object <- callNextMethod()
object@nodes <- getNodes(object)
object
})