Janko Thyson
2010-Nov-23 21:11 UTC
[Rd] Reference Classes: removing methods -> implications for objects/instances of that class
Dear list, just to make sure that I understand 'unregistering' methods for S4 reference classes correctly: If I registered a method and want to 'unregister' (i.e. remove) this method again, objects/instance created of the respective class still feature the removed method until I do an explicit reassign ('my.instance <- getRefClass("Classname")$new()'), right? setRefClass("Shab", fields=list(a="numeric")) # Register method getRefClass("Shab")$methods(list(aSquare=function() a^2)) getRefClass("Shab")$methods() # Create instance shab <- getRefClass("Shab")$new() shab$a <- 10 # Use method shab$aSquare() # Remove method getRefClass("Shab")$methods(list(aSquare=NULL)) getRefClass("Shab")$methods() # Gone. shab$aSquare() # Still possible shab <- getRefClass("Shab")$new() shab$aSquare() # Not possible anymore Is it also possible to remove a method so that all instances do not feature the respective method anymore without having to resort to an explicit reassign? Or is this technically not possible or not a desired feature? TIA, Janko ########## SYSTEM INFO ########## Windows XP SP3 R 2.12.0 (patched as of 2010-11-22) Eclipse 3.6.1 (Helios) StatET 0.9.x ###############################
Vitalie S.
2010-Nov-27 10:13 UTC
[Rd] Reference Classes: removing methods -> implications for objects/instances of that class
"Janko Thyson" <janko.thyson at ku-eichstaett.de> writes:> Dear list, > > just to make sure that I understand 'unregistering' methods for S4 reference > classes correctly: > > If I registered a method and want to 'unregister' (i.e. remove) this method > again, objects/instance created of the respective class still feature the > removed method until I do an explicit reassign ('my.instance <- > getRefClass("Classname")$new()'), right? > > setRefClass("Shab", fields=list(a="numeric")) > # Register method > getRefClass("Shab")$methods(list(aSquare=function() a^2)) > getRefClass("Shab")$methods() > > # Create instance > shab <- getRefClass("Shab")$new() > shab$a <- 10 > # Use method > shab$aSquare() > > # Remove method > getRefClass("Shab")$methods(list(aSquare=NULL)) > getRefClass("Shab")$methods() # Gone. > shab$aSquare() # Still possibleIf I am not mistaken methods are cached in the object during the first invocation. So, if you change the method after the method has been used with the instance. The object will not see the change. This can not happen with the fields though, because they can not be installed after the generator class is defined.> > shab <- getRefClass("Shab")$new() > shab$aSquare() # Not possible anymore > > Is it also possible to remove a method so that all instances do not feature > the respective method anymore without having to resort to an explicit > reassign? Or is this technically not possible or not a desired feature? > > TIA, > Janko > > ########## SYSTEM INFO ########## > Windows XP SP3 > R 2.12.0 (patched as of 2010-11-22) > Eclipse 3.6.1 (Helios) > StatET 0.9.x > ###############################
Possibly Parallel Threads
- Reference classes: accessor functions via 'getRefClass(...)$accessors(...)'
- Reference Classes: how to clone/copy instances?
- Ref classes: can I register fields as I register methods?
- How can I write methods for 'as()'?
- Reference Classes: shortcut like 'isS4' for Ref Classes?