[Rd] Reference Classes: how to clone/copy instances?
John Chambers
jmc at r-project.org
Thu Nov 25 18:05:37 CET 2010
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
>
More information about the R-devel
mailing list