[Rd] How to overload the assignment operator?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Nov 13 21:05:16 CET 2007
On Tue, 13 Nov 2007, "Jens Oehlschlägel" wrote:
> Thank you Brian,
>
>> setReplaceMethod() is just syntactic sugar for setting an S4 method on a
>> replacement function (read the function definition to see so). You can
>> set S3 replacement methods, and the S4 mechanism just piggy-backs on that.
>
> So I understand that setReplaceMethod will not help.
>
>> I think the conceptual problem is that the assignment operator does not
>> actually do any copying: it creates a binding of a symbol to a value.
>> Any copying which occurs happens when the value is (potentially) changed.
>
> I would be even happier if the cloning would only occur on any attempt to change the external pointer / proxy-object.
>
>> There is no provision for that to depend on the class (rather than the
>> type) of the object.
>
> Mh, unless the internal copying mechanism would call a clone generic for non-atomic objects
But as I said, there is no provision for that. Nor is there going to be.
One reason is performance, as Simon has hinted. Another is consistency:
duplication might well be called from places where class is being ignored.
>> Since external pointers are never duplicated, you
>> ought to be able to take advantage of that to design the copying semantics
>> you want.
>
> How that? How do I know that any user has assigned/modified the external pointer (or a proxy object containing the external pointer) such that I can invoke the cloning?
I don't even know what you want to do. But I don't think copying is the
place to find out if a user changed an object: presumably it was done via
your interface.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-devel
mailing list