From oehl_list at gmx.de  Tue Nov 13 17:00:23 2007
From: oehl_list at gmx.de (=?iso-8859-1?Q?=22Jens_Oehlschl=E4gel=22?=)
Date: Tue, 13 Nov 2007 17:00:23 +0100
Subject: [Rd] How to overload the assignment operator?
Message-ID: <20071113160023.247410@gmx.net>

Thanks Simon,

> You cannot use S3 here, because you want to dispatch on the *second*  
> argument.

"<-" <- function(x, value)UseMethod("<-", value)
DOES dispatch on the second argument (see the dispatchsecond example below)

> Why don't you take the external pointer approach that many others take  
> to provide proxy objects to external data? (DB access, mem-mapped  
> files, cross-language objects, etc.) That allows you to define your  
> storage semantics very efficiently in C. You can still choose to  
> define any syntactic sugar you want in either S3 or S4.

I AM using the external pointer approach and this works verly well - if one tolerates that the external data is not duplicated when the proxy object is copied. I was wondering however, if it is possible to perfectly mimic R's copying semantics: duplicate external object (and the external pointer) on assignment (or even better only on modify after assignment).

Best regards

Jens Oehlschl?gel

> dispatchsecond <- function(first, second)
+ UseMethod("dispatchsecond", second)
> 
> dispatchsecond.default <- function(first, second){
+ cat("here default\n")
+ }
> 
> dispatchsecond.ff <- function(first, second){
+ cat("here ff\n")
+ }
> 
> default <- 1
> ff <- 1
> class(ff) <- "ff"
> 
> dispatchsecond(1,default)
here default
> dispatchsecond(1,ff)
here ff
> 
--



[Rd] How to overload the assignment operator?
=?iso-8859-1?Q?=22Jens_Oehlschl=E4gel=22?=