Last data update: 2014.03.03

R: A replacement for unlist() that does not mangle the names
unlist2R Documentation

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

Description

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

Usage

  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)

Herve Pages

See Also

unlist

Examples

  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...

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(AnnotationDbi)
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, xtabs

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

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, 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, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

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 objects are masked from 'package:base':

    colMeans, colSums, expand.grid, rowMeans, rowSums

> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/AnnotationDbi/unlist2.Rd_%03d_medium.png", width=480, height=480)
> ### Name: unlist2
> ### Title: A replacement for unlist() that does not mangle the names
> ### Aliases: unlist2
> ### Keywords: utilities manip
> 
> ### ** Examples
> 
>   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)
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 
>   unlist2(x)
 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 
> 
>   library(hgu95av2.db)
Loading required package: org.Hs.eg.db


>   egids <- c("10", "100", "1000")
>   egids2pbids <- mget(egids, revmap(hgu95av2ENTREZID))
>   egids2pbids
$`10`
[1] "38912_at"

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

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

> 
>   unlist(egids2pbids)   # 1001, 1002, 10001 and 10002 are not real
         10        1001        1002       10001       10002 
 "38912_at"  "41654_at"    "907_at"   "2053_at" "2054_g_at" 
>                         # Entrez ids but are the result of unlist()
>                         # mangling the names!
> 
>   unlist2(egids2pbids)  # much cleaner! yes the names are not unique
         10         100         100        1000        1000 
 "38912_at"  "41654_at"    "907_at"   "2053_at" "2054_g_at" 
>                         # but at least they are correct...
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>