Re: [Rd] How to overload the assignment operator?

From: Jens Oehlschlägel <oehl_list_at_gmx.de>
Date: Tue, 13 Nov 2007 17:00:23 +0100


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
>

--

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue 13 Nov 2007 - 16:13:21 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 13 Nov 2007 - 18:30:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.