bug in IRanges::disjoin and strange behavior of c
1
0
Entering edit mode
@kasper-daniel-hansen-2979
Last seen 10 months ago
United States
On Jan 29, 2010, at 16:11 PM, Michael Lawrence wrote: > c behaviour > ========= > > It seems to behave strangely in connection with do.call and a named list: > > ir = IRanges(start = 1:3, end = 2:4) > do.call(c, list(ir, ir)) ## What I expect, a single IRange with 6 entries. > do.call(c, list(ir1 = ir, ir2 = ir)) ## This I don't get > > $ir1 > IRanges of length 3 > start end width > [1] 1 2 2 > [2] 2 3 2 > [3] 3 4 2 > > $ir2 > IRanges of length 3 > start end width > [1] 1 2 2 > [2] 2 3 2 > [3] 3 4 2 > > My guess is that this is something with c and method dispatching and do.call. > > > Yes, it is known that there is strange behavior here. The combination of dispatching on a .Primitive and the "..." signature pushes things a bit too far. 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. Kasper
IRanges IRanges • 594 views
ADD COMMENT
0
Entering edit mode
@herve-pages-1542
Last seen 19 hours ago
Seattle, WA, United States
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
ADD COMMENT

Login before adding your answer.

Traffic: 884 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6