From janko.thyson at ku-eichstaett.de  Wed Nov 24 10:47:40 2010
From: janko.thyson at ku-eichstaett.de (Janko Thyson)
Date: Wed, 24 Nov 2010 10:47:40 +0100
Subject: [Rd] Reference Classes: how to clone/copy instances?
Message-ID: <009601cb8bbc$a288d4e0$e79a7ea0$@thyson@ku-eichstaett.de>

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



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