[BioC] bug in IRanges::disjoin and strange behavior of c

Hervé Pagès hpages at fhcrc.org
Tue Feb 2 17:06:47 CET 2010


Hi Kasper,

Kasper Daniel Hansen wrote:
[...]
> 
> What I don't get is why this works when the list has no names and why it fails with a named list.  This is potentially dangerous behavior.

It's a bug in the dispatch code.

setClass("A", representation(aa="integer"))

setMethod("c", "A",
     function(x, ..., recursive=FALSE)
     {
         if (missing(x))
             args <- unname(list(...))
         else
             args <- unname(list(x, ...))
         ans_aa <- unlist(lapply(args, function(x) x at aa))
         new(class(args[[1L]]), aa=ans_aa)
     }
)

The following works as expected (in R-2.11, not in R-2.10):

 > a <- new("A", aa=3:-2)
 > c(a, a)
An object of class "A"
Slot "aa":
  [1]  3  2  1  0 -1 -2  3  2  1  0 -1 -2

 > c(x=a, a)
An object of class "A"
Slot "aa":
  [1]  3  2  1  0 -1 -2  3  2  1  0 -1 -2

 > c(a1=a, a2=a)
An object of class "A"
Slot "aa":
  [1]  3  2  1  0 -1 -2  3  2  1  0 -1 -2

But when class A and its "c" method are defined in a package, then
dispatch fails:

 > library(mypkg)
 > c(a1=a, a2=a)
$a1
An object of class "A"
Slot "aa":
[1]  3  2  1  0 -1 -2


$a2
An object of class "A"
Slot "aa":
[1]  3  2  1  0 -1 -2

'mypkg' contains a single R file with the definitions of class A
and its "c" method. It doesn't even need to have a namespace.

Anybody's willing to report this to R-devel?

Cheers,
H.


> 
> Kasper
> 
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor

-- 
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M2-B876
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpages at fhcrc.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319



More information about the Bioconductor mailing list