[R] Is there a way to update a method on an existing Reference Class object?
Peder Bacher
pb at imm.dtu.dk
Wed Jan 4 15:09:44 CET 2012
Hi
Being able to do object oriented programming in R is really good. I
now started using the Reference Classes and really like it.
Though, I have one problem: I cannot find a way to update a method on
an existing object.
The flexibility that scripting gives (really needed for interactive
data analysis) is lost if everything have to be recalculated all the
time.
For example I would normally work something like this:
cl1 <- setRefClass("cl1",
fields=list(x="data.frame"),
methods=list(
init=function(){"Read and process data"},
fitModel=function(){"Fit different kind of models and keep the
results in x and other fields"},
plotFit1=function(){"Plot the fit one way"},
plotFit2=function(){"Plot the fit in another way way"})
)
I would then initialize it and run the functions on it:
cl1Object <- cl1$new()
...
The problem then comes if I need to change something in one of the
methods, because I then have to run all the initialization and fitting
again, since the change is done to "cl1" and not "cl1Object", of
course.
The reference class documentation states that it is not possible since
this would give problems with inheritance etc. Is there a workaround
to this?
The very best
Peder
More information about the R-help
mailing list