Re: [Rd] Reference Classes: how to clone/copy instances?

From: John Chambers <jmc_at_r-project.org>
Date: Thu, 25 Nov 2010 09:05:37 -0800

No reference class method explicitly does this, but it's a natural utility. Some form of $copy() will be added. It needs a shallow/deep option; i.e., if a field is itself a reference class object, should that field be cloned as well. The full reflectance available should make a single method (for the "envRefClass") work generally, although classes with non-standard accessor functions may need to have their own method.

Any contributions or suggestions are welcome, particularly with respect to features from other OOP languages that should be accommodated. Lazy copy would be attractive, but harder to implement.

John

On 11/24/10 1:47 AM, Janko Thyson wrote:
> Dear list,
>
> I don't know what's the correct term for this in the OOP context, but is it
> possible to "clone"/copy an instance of a reference class (say 'a') so that
> I get an *autonomous* second instance 'b'? Autonomous in the sense that
> changes to 'a' do not affect 'b'.
>
> I know that this is somewhat against the pass-by-reference paradigm, but the
> motive behind this is to generalize the 'undo()' functionality described in
> the example of 'setRefClass()' to entire objects: I'd like to generate
> "images" of my object via a '$imageAdd()" method in order to generate a
> change history of the object (images are assigned to a field '.IMAGES' of
> class 'environment') that I can "load()" on demand to undo changes to my
> object.
>
> Obviously, simply assigning 'b<- a' does not work with respect to autonomy.
> Nor does exporting the object via 'b<- a$export(Class="A")'.
> I thought about creating a new instance b and then defining a function that
> maps the field values from a to b:
>
> b<- getRefClass("A")$new()
> fieldsMap(src=a, tgt=b)
>
> Is there already some functionality I can use?
>
> Thanks,
> 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
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 25 Nov 2010 - 17:08:08 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 Thu 25 Nov 2010 - 17: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