Re: [Rd] Reference Classes: removing methods -> implications for objects/instances of that class

From: Vitalie S. <spinuvit.list_at_gmail.com>
Date: Sat, 27 Nov 2010 11:13:42 +0100

"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 possible

If 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
> ###############################



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat 27 Nov 2010 - 10:16:41 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 27 Nov 2010 - 23:10:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive