Flattening Marker Lists

Description

flatten is an S4 generic function that flattens objects by unfolding their inner levels, like what unlist does for list objects.

Usage

flatten(object, ...)

S4 (list)
`flatten`(object, use.names = FALSE)

S4 (MarkerList)
`flatten`(object, use.names = FALSE, size = NA)

Arguments

object
the object to be flattened
...
extra arguments to allow extension. See each method's description for more details.
use.names
logical that indicates if the top level names, i.e. the names of list (e.g., the cell types) should be used instead of the names of each vector element.
size
an integer that specifies the desired size of the result vector, which is used only if the marker are identified by their index. It is useful if one wants to use the result with data of known -- greater -- dimension.

Methods

  1. flattensignature(object = "list"): For list objects this is equivalent to unlist2.

  2. flattensignature(object = "MarkerList"): For MarkerList objects the conversion is similar to what unlist would do, but argument use.names is used slightly differently.

    Secondly, the names of the main elements are append to the marker names (like unlist does if use.names=TRUE) only for marker lists that contain numeric values (e.g. specificity scores). In the other cases, they are used either as values for character marker lists or as duplicated names for integer marker lists.

Examples


l <- list(1,2,3,c(4,5,6))
flatten(l)
## [1] 1 2 3 4 5 6
nl <- setNames(l, letters[1:length(l)])
flatten(nl)
## [1] 1 2 3 4 5 6
flatten(nl, use.names=TRUE)
## a b c d d d 
## 1 2 3 4 5 6
ml <- rMarkerList(3, names=TRUE)
flatten(ml)
##  [1] "Marker.3"  "Marker.2"  "Marker.1"  "Marker.7"  "Marker.8" 
##  [6] "Marker.4"  "Marker.6"  "Marker.5"  "Marker.9"  "Marker.14"
## [11] "Marker.10" "Marker.18" "Marker.13" "Marker.12" "Marker.17"
## [16] "Marker.16" "Marker.11" "Marker.15"
flatten(ml, use.names=TRUE)
##  Marker.3  Marker.2  Marker.1  Marker.7  Marker.8  Marker.4  Marker.6 
##   "Type1"   "Type1"   "Type1"   "Type2"   "Type2"   "Type2"   "Type2" 
##  Marker.5  Marker.9 Marker.14 Marker.10 Marker.18 Marker.13 Marker.12 
##   "Type2"   "Type2"   "Type3"   "Type3"   "Type3"   "Type3"   "Type3" 
## Marker.17 Marker.16 Marker.11 Marker.15 
##   "Type3"   "Type3"   "Type3"   "Type3"

See also

unlist