Skip to content
Prev 5466 / 21312 Next

[Bioc-devel] Subsetting Lists by Lists

Hi Michael,
On 04/01/2014 07:21 AM, Michael Lawrence wrote:
Before I reworked the subsetting code last year, subsetting a List by
a shorter List was not supported. For example, in BioC 2.11:

   > cvg
   SimpleRleList of length 3
   $chr1
   integer-Rle of length 11 with 4 runs
     Lengths: 4 1 5 1
     Values : 1 2 3 0

   $chr2
   integer-Rle of length 12 with 5 runs
     Lengths: 1 1 1 7 2
     Values : 0 1 2 3 0

   $chr3
   integer-Rle of length 13 with 6 runs
     Lengths: 6 1 1 1 1 3
     Values : 0 1 2 3 4 0

   > cvg[IntegerList(1:5)]
   Error in seqselect(x, i) :
     'length(start)' must equal 'length(x)' when 'end' and 'width' are NULL

When I reworked the subsetting code, I allowed this and I chose the
current behavior because that returns an object that has the length
of the subscript, which is consistent with what subsetting does in
general, and, most importantly, with what subsetting by a named List
does in particular:

   > cvg[IntegerList(chr2=1:5)]
   RleList of length 1
   $chr2
   integer-Rle of length 5 with 4 runs
     Lengths: 1 1 1 2
     Values : 0 1 2 3

Or said otherwise, I thought it might be a strange thing that the
subscript is not recycled when it's named and recycled when it's
not named. But maybe it's a bigger surprise that 'x[IntegerList(1:5)]'
is only extracting the first 5 elements of 'x[[1]]', and I can see
that it would be convenient to have a simple way to extract them
from *each* list element in 'x'.

Too late to change this for this release unfortunately.

H.

  
    
Message-ID: <533AFEBC.9020101@fhcrc.org>
In-Reply-To: <4284_1396362088_533ACB68_4284_3311_1_CAOQ5Nyeztnz117f5VMtG5kmUR9jPrF1NbZyMBvH7QG-cc2anBQ@mail.gmail.com>