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

From: Janko Thyson <janko.thyson_at_ku-eichstaett.de>
Date: Wed, 24 Nov 2010 10:47:40 +0100


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 Received on Wed 24 Nov 2010 - 09:51:09 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:20: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