Given a list 'x' of R objects from the same class and same format, unlist simplifies it to produce a new R object which contains all the initial components which in 'x' object.

unlist(x, recursive = TRUE, use.names = TRUE)

Arguments

x

Any list R object.

recursive

Logical. Should unlisting be applied to list components of x?

use.names

Logical. Should names be preserved?

Details

This is a method to extend unlist generic function to handle any list of objects from the same class.

Examples

gr1 <-GRanges(seqnames = 'chr2', ranges = IRanges(3, 6), strand = '+',
score = 5L, GC = 0.45)

gr2 <- GRanges(seqnames = c('chr1', 'chr1'), ranges = IRanges(c(7,13),
width = 3), strand = c('+', '-'), score = 3:4, GC = c(0.3, 0.5))

gr3 <- GRanges(seqnames = c('chr1', 'chr2'),
ranges = IRanges(c(1, 4), c(3, 9)), strand = c('-', '-'),
score = c(6L, 2L), GC = c(0.4, 0.1))

grl <- list('gr1' = gr1, 'gr2' = gr2, 'gr3' = gr3)
base::unlist(grl) # The default unlist does not work
#> $gr1
#> GRanges object with 1 range and 2 metadata columns:
#>       seqnames    ranges strand |     score        GC
#>          <Rle> <IRanges>  <Rle> | <integer> <numeric>
#>   [1]     chr2       3-6      + |         5      0.45
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
#> 
#> $gr2
#> GRanges object with 2 ranges and 2 metadata columns:
#>       seqnames    ranges strand |     score        GC
#>          <Rle> <IRanges>  <Rle> | <integer> <numeric>
#>   [1]     chr1       7-9      + |         3       0.3
#>   [2]     chr1     13-15      - |         4       0.5
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
#> 
#> $gr3
#> GRanges object with 2 ranges and 2 metadata columns:
#>       seqnames    ranges strand |     score        GC
#>          <Rle> <IRanges>  <Rle> | <integer> <numeric>
#>   [1]     chr1       1-3      - |         6       0.4
#>   [2]     chr2       4-9      - |         2       0.1
#>   -------
#>   seqinfo: 2 sequences from an unspecified genome; no seqlengths
#> 
unlist(grl)
#> GRanges object with 5 ranges and 2 metadata columns:
#>       seqnames    ranges strand |     score        GC
#>          <Rle> <IRanges>  <Rle> | <integer> <numeric>
#>   [1]     chr2       3-6      + |         5      0.45
#>   [2]     chr1       7-9      + |         3      0.30
#>   [3]     chr1     13-15      - |         4      0.50
#>   [4]     chr1       1-3      - |         6      0.40
#>   [5]     chr2       4-9      - |         2      0.10
#>   -------
#>   seqinfo: 2 sequences from an unspecified genome; no seqlengths