Skip to content
Prev 3658 / 21312 Next

[Bioc-devel] annotation() to BiocGenerics?

On 09/21/2012 09:26 AM, Robert Castelo wrote:
I was more struck by this usage

   eScoEset <- Biobase::`annotation<-`(eScoEset, "")

which I would have written, if following your preferred style,

   Biobase::annotation(eScoEset) <- ""

(I personally would have written annotation(eScoEset) <- "").

There is a performance difference (:: is a function call, and there are 
several symbol look-ups involved) but I doubt that would be a serious 
concern in a seldom-used function (different, though if this were called 
in a large loop).

There is a subtle issue relevant to S4, though the implementation of 
annotation<- shields you from this -- note how the following changes the 
value of 'b' as well as 'a'

 > setClass("A", representation(value="numeric"))
 > a <- b <- new("A", value=1)
 > `slot<-`(a, "value", value=2)
An object of class "A"
Slot "value":
[1] 2

 > b
An object of class "A"
Slot "value":
[1] 2

which does not occur for slot(a, "value") <- 2

For what it's worth, the reason for your code breakage is that the 
signature of annotation<- changed from function(object, value) to 
function(object, ..., value). This is desirable because it allows 
methods to define additional arguments to the replacement function, and 
does not break the replacement method when used as annotation(eScoEset) 
<- "" (replacement methods match the right hand side to the last 
argument) but obviously caused problems for your approach.

Martin