flatten
is an S4 generic function that flattens
objects by unfolding their inner levels, like what
unlist
does for list
objects.
flatten(object, ...) S4 (list) `flatten`(object, use.names = FALSE) S4 (MarkerList) `flatten`(object, use.names = FALSE, size = NA)
signature(object = "list")
: For
list
objects this is equivalent to
unlist2
.
signature(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.
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"
unlist