From ripley at stats.ox.ac.uk  Tue Nov 13 16:04:43 2007
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Tue, 13 Nov 2007 15:04:43 +0000 (GMT)
Subject: [Rd] How to overload the assignment operator?
In-Reply-To: <20071113141905.267830@gmx.net>
References: <20071113141905.267830@gmx.net>
Message-ID: <Pine.LNX.4.64.0711131429420.9317@gannet.stats.ox.ac.uk>

On Tue, 13 Nov 2007, "Jens Oehlschl?gel" wrote:

> Thanks Matthias,
>
>> are you looking for "setReplaceMethod"?
>
> So far the package I m writing has avoided using anything from S4 and 
> the implications of touching S4 are not clear to me. The package aims on 
> providing an alternative to 'atomic' data stored in ram, i.e. large 
> atomic data stored on disk. I need some advice how to do this maximally 
> performant, which probably means pure S3!?

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.

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. 
There is no provision for that to depend on the class (rather than the 
type) of the object.  Since external pointers are never duplicated, you 
ought to be able to take advantage of that to design the copying semantics 
you want.

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


[Rd] How to overload the assignment operator?
Prof Brian Ripley