You want to call the trace
method of the instance object.
a$trace("setFields")
This is the implementation that you want for the setFields
method.
AB.setFields <- function(...) {
dots <- list(...)
fieldNames <- names(dots)
for(i in seq_along(dots))
{
assign(fieldNames[[i]], dots[[i]], attr(.self, ".xData"))
}
}
a$setFields(name="aaa",var2=factor(1:3))
There's probably some syntactic sugar I've missed to make this prettier, but to get all your fields, you can use
AB.getFields <- function(){
mget(
names(.refClassDef@fieldClasses),
envir = attr(.self, ".xData")
)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…