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

From: Matthias Kohl <Matthias.Kohl_at_stamats.de>
Date: Tue, 13 Nov 2007 14:52:53 +0100

are you looking for "setReplaceMethod"?
hth
Matthias

Jens Oehlschlägel wrote:
> Dear all,
>
> what is the proper way to make the assignment operator generic and define methods depending on the class of the assigned value?
>
> Best regards
>
>
> Jens Oehlschlägel
>
> P.S. I vaguely remember that this was possible in S+. In R I tried to no avail:
>
> # using this like h<-1:3 gives Error: in `<-.default`(h, 1:3) : invalid (do_set) left-hand side to assignment
> "<-.default" <- get("<-")
>
> # using this does fail on subassignments like: h <- 1:3 ; h[1] <- 7 (h still is 1:3)
> "<-.default" <- function(x, value){
> assign(deparse(substitute(x)), value, parent.frame())
> invisible(x)
> }
>
> # this seems to work
> "<-" <- function(x, value){
> UseMethod("<-", value)
> }
>
> # whenever the assigned value has class 'ff' I want to do execute something like
> "<-.ff" <- function(x, value){
> y <- clone(value)
> assign(deparse(substitute(x)), y, parent.frame())
> y
> }
>
>
>
>> version
>>
> _
> platform i386-pc-mingw32
> arch i386
> os mingw32
> system i386, mingw32
> status
> major 2
> minor 6.0
> year 2007
> month 10
> day 03
> svn rev 43063
> language R
> version.string R version 2.6.0 (2007-10-03)
>
> --
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 13 Nov 2007 - 13:56:43 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 - 14: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.