[R] 'callNextMethod' in a '[<-' function does not work ?
Martin Morgan
mtmorgan at fhcrc.org
Fri Dec 9 22:14:09 CET 2011
On 12/09/2011 10:15 AM, cgenolin wrote:
> Hi the list,
>
> I try to use callNextMethod in a setteur ([<-) but it does not work.
> Any raison ?
> Any other option ?
>
> --- 8< ------------------
> ### Class B0 ###
> setClass("B0" , representation(b0 = "numeric"))
> setReplaceMethod("[","B0",function(x,i,j,value){x at b0<- -value})
return modified x, and match signature to getGeneric("[<-")
setClass("B0" , representation(b0 = "numeric"))
setReplaceMethod("[","B0", function(x,i,j, ..., value) {
x at b0 <- -value
x
})
>
> a<- new("B0")
> a at b0<- 3
> a
> a["b0"]<- 3
> a
>
>
> ### Class B1 ###
> setClass("B1", representation(b1 = "character"), contains = "B0")
> setReplaceMethod("[","B1",function(x,i,j,value){
> value<- value*2
> callNextMethod()
> })
provide arguments to callNextMethod, reflecting updated value
setClass("B1", representation(b1 = "character"), contains = "B0")
setReplaceMethod("[","B1",function(x,i,j, ..., value){
value <- value*2
callNextMethod(x, i, j, ..., value=value)
})
> b<- new("B1")
> try(b["b0"]<- 5)
of course "b0" is not being used to index here.
Martin
> --- 8< ------------------
>
> Christophe
>
> --
> View this message in context: http://r.789695.n4.nabble.com/callNextMethod-in-a-function-does-not-work-tp4177669p4177669.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109
Location: M1-B861
Telephone: 206 667-2793
More information about the R-help
mailing list