unlist2: A replacement for unlist() that does not mangle the names

Description Usage Arguments Details Author(s) See Also Examples

View source: R/unlist2.R

Description

unlist2 is a replacement for base::unlist() that does not mangle the names.

Usage

1
  unlist2(x, recursive=TRUE, use.names=TRUE, what.names="inherited")

Arguments

x, recursive, use.names

See ?unlist.

what.names

"inherited" or "full".

Details

Use this function if you don't like the mangled names returned by the standard unlist function from the base package. Using unlist with annotation data is dangerous and it is highly recommended to use unlist2 instead.

Author(s)

Hervé Pagès

See Also

unlist

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
  x <- list(A=c(b=-4, 2, b=7), B=3:-1, c(a=1, a=-2), C=list(c(2:-1, d=55), e=99))
  unlist(x)
  unlist2(x)

  library(hgu95av2.db)
  egids <- c("10", "100", "1000")
  egids2pbids <- mget(egids, revmap(hgu95av2ENTREZID))
  egids2pbids

  unlist(egids2pbids)   # 1001, 1002, 10001 and 10002 are not real
                        # Entrez ids but are the result of unlist()
                        # mangling the names!

  unlist2(egids2pbids)  # much cleaner! yes the names are not unique
                        # but at least they are correct...

Example output

Loading required package: stats4
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, sd, var, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colMeans, colSums, colnames, do.call,
    duplicated, eval, evalq, get, grep, grepl, intersect, is.unsorted,
    lapply, lengths, mapply, match, mget, order, paste, pmax, pmax.int,
    pmin, pmin.int, rank, rbind, rowMeans, rowSums, rownames, sapply,
    setdiff, sort, table, tapply, union, unique, unsplit, which,
    which.max, which.min

Loading required package: Biobase
Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

Loading required package: IRanges
Loading required package: S4Vectors

Attaching package: 'S4Vectors'

The following object is masked from 'package:base':

    expand.grid

A.b  A2 A.b  B1  B2  B3  B4  B5   a   a  C1  C2  C3  C4 C.d C.e 
 -4   2   7   3   2   1   0  -1   1  -2   2   1   0  -1  55  99 
 b  A  b  B  B  B  B  B  a  a  C  C  C  C  d  e 
-4  2  7  3  2  1  0 -1  1 -2  2  1  0 -1 55 99 
Loading required package: org.Hs.eg.db


$`10`
[1] "38912_at"

$`100`
[1] "41654_at" "907_at"  

$`1000`
[1] "2053_at"   "2054_g_at"

         10        1001        1002       10001       10002 
 "38912_at"  "41654_at"    "907_at"   "2053_at" "2054_g_at" 
         10         100         100        1000        1000 
 "38912_at"  "41654_at"    "907_at"   "2053_at" "2054_g_at" 

AnnotationDbi documentation built on Nov. 8, 2020, 4:50 p.m.