[R] the unwanted persistence of refClass methods

Ross Boylan ross at biostat.ucsf.edu
Thu Feb 13 20:16:21 CET 2014


Redefining methods of a refClass does not change the methods for 
existing instances.  I found this somewhat surprising, and also pretty 
inconvenient for debugging.

The documentation for reference classes does say that their methods 
should be minimalist, which I suppose is partly because of this behavior.

Is there a way around this behavior apart from passing the pieces of the 
old instance to the new constructor, or putting all computations in not 
class functions?

> foo <- setRefClass("foo", methods=list(f=function(x) 3*x))
> a <- foo()
> a$f(10)
[1] 30
> foo <- setRefClass("foo", method=list(f=function(x) 2*x))
> a$f(10)
[1] 30
> b <- foo()
> b$f(10)
[1] 20

Ross Boylan



More information about the R-help mailing list