Question: unlist doesn't work for IRanges
gravatar for li lilingdu
3 months ago by
li lilingdu450
li lilingdu450 wrote:


> library(IRanges)
> dat<-IRanges(1,10)
> unlist(dat)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘getListElement’ for signature ‘"IRanges"’
> as(dat,'vector')
Error in as.vector(from) : 
  no method for coercing this S4 class to a vector
> as(dat,'integer')
Error in as.vector(x, mode = "integer") : 
  no method for coercing this S4 class to a vector


> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

[1] LC_COLLATE=Chinese (Simplified)_China.936  LC_CTYPE=Chinese (Simplified)_China.936    LC_MONETARY=Chinese (Simplified)_China.936 LC_NUMERIC=C                              
[5] LC_TIME=Chinese (Simplified)_China.936    

attached base packages:
[1] stats4    parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] IRanges_2.14.10     S4Vectors_0.18.2    BiocGenerics_0.26.0

loaded via a namespace (and not attached):
[1] compiler_3.5.0
ADD COMMENTlink modified 3 months ago by James W. MacDonald47k • written 3 months ago by li lilingdu450
gravatar for James W. MacDonald
3 months ago by
United States
James W. MacDonald47k wrote:

When behaviors change the first place to look is the NEWS file for the respective package. From IRanges:



    o The Ranges virtual class is now the common parent of the IRanges,
      GRanges, and GAlignments classes (GRanges and GAlignments are defined
      in the GenomicRanges and GenomicAlignments packages, respectively).
      More precisely, Ranges is a virtual class that now serves as the parent
      class for any class that represents a vector of ranges. The ranges can
      be integer ranges (i.e. ranges on the space of integers) like in an
      IRanges object, or genomic ranges (i.e. ranges on a genome) like in a
      GRanges object. Note that because Ranges extends List, all Ranges
      derivatives are considered list-like objects. This means that GRanges
      objects and their derivatives are considered list-like objects, which
      is new (even though [[ don't work on them yet, this will be implemented
      in Bioconductor 3.8).

    o Similarly the RangesList virtual class is now the common parent of the
      IRangesList, GRangesList, and GAlignmentsList classes.

    o IRanges objects don't support [[, unlist(), as.list(), lapply(), and
      as.integer() anymore. This is a temporary situation only. These
      operations will be re-introduced in Bioconductor 3.8 but with a
      different semantic. The overall goal of all these changes is to bring
      more consitency between IRanges and GRanges objects (GRanges objects will
      also support [[, unlist(), as.list(), and lapply() in Bioconductor 3.8).
      Non-exported IRanges:::unlist_as_integer() helper is a temporary
      replacement for what unlist() and as.integer() used to do a IRanges
ADD COMMENTlink written 3 months ago by James W. MacDonald47k
gravatar for Gordon Smyth
3 months ago by
Gordon Smyth34k
Walter and Eliza Hall Institute of Medical Research, Melbourne, Australia
Gordon Smyth34k wrote:

Why would you expect unlist() to work on something that isn't a list? What made you think it would work on an IRanges object? What did you expect it to do?

> is.list(dat)
ADD COMMENTlink modified 3 months ago • written 3 months ago by Gordon Smyth34k

Hi ,

Thanks for your reply.

> library(S4Vectors)
> library(IRanges)
> is(IRanges(1,10),"List")


in previous version of IRanges and S4Vectors 


would give the result of integer vector   1:10

And there exists method of  'unlist' for 'List':

> showMethods('unlist',class='List',inc=T)
Function: unlist (package base)
function (x, recursive = TRUE, use.names = TRUE) 
    if (!isTRUEorFALSE(use.names)) 
        stop("'use.names' must be TRUE or FALSE")
    if (length(x) == 0L) {
        elt_type <- elementType(x)
        if (isVirtualClass(elt_type)) 
    xx <- unname(as.list(x))
    if (length(dim(xx[[1L]])) < 2L) {
        unlisted_x <-, xx)
    else {
        unlisted_x <-, xx)
    if (use.names) 
        unlisted_x <- set_unlisted_names(unlisted_x, x)



ADD REPLYlink modified 3 months ago • written 3 months ago by li lilingdu450

I see, you're quite right. We'll have to wait for an IRanges expert to respond.

ADD REPLYlink modified 3 months ago • written 3 months ago by Gordon Smyth34k

For now I guess you'll just have to use IRanges:::unlist_as_integer(). I'm hoping that there is a way to achieve the same effect in the future using an exported entry point.

ADD REPLYlink written 11 weeks ago by Michael Lawrence10k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 206 users visited in the last hour