我收到以下错误,我认为这是因为解释器认为我调用了该函数.self$getFields
。
a<-A$new(var1=list(B$new(var1="a"),B$new(var1="b")))
a$test()
[1] Error in getFields(l, c("var1")) : unused argument (c("var1"))
AB.getFields<-function(keys){
vars<-mget(names(.refClassDef@fieldClasses), envir = attr(.self, ".xData"))
return(vars[keys])
}
B<-setRefClass(Class = "B"
,fields = list(var1 = "character")
,methods = list(getFields=AB.getFields
,initialize=function(...) {
usingMethods("getFields")
callSuper(...)
}
)
)
A<-setRefClass(Class = "A"
,fields = list(var1 = "list")
,methods = list(getFields=AB.getFields,
test=function() {
getFields(.self$var1,c("var1"))
}))
setGeneric("getFields", function(object, ...) standardGeneric("getFields"))
setMethod(getFields, "list", function(object, ...) lapply(object,function(e,...) e$getFields(...)))