[Rd] How to overload the assignment operator?
"Jens Oehlschlägel"
joehl at gmx.de
Tue Nov 13 16:39:02 CET 2007
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
>
--
More information about the R-devel
mailing list