List objects are Vector objects with a
The List class serves a similar role as list in base R.
It adds one slot, the
elementType slot, to the two slots shared by
all Vector objects.
elementType slot is the preferred location for List
subclasses to store the type of data represented in the sequence. It is
designed to take a character of length 1 representing the class of the
sequence elements. While the List class performs no validity checking
elementType, if a subclass expects elements to be of a
given type, that subclass is expected to perform the necessary validity
checking. For example, the subclass IntegerList (defined
in the IRanges package) has
elementType = "integer" and its
validity method checks if this condition is TRUE.
To be functional, a class that inherits from List must define at least
"[[" method (in addition to the minimum set of Vector
List objects are typically constructed using one of the 3 following methods:
Use of a constructor function. Many constructor functions are
provided for List objects e.g.
Which one to use depends on the particular type of List object
to construct. The name of a constructor function is always
the name of a valid class. If it's the name of a concrete
class (e.g. the
defined in the GenomicRanges package), then the constructor
function returns an instance of that class. If it's the name of a
virtual class (e.g. the
List constructor defined in
this package, or the
IntegerRangesList constructors defined in the
IRanges package), then the returned object belongs to a
concrete subclass of that virtual class. Which subclass exactly
depends on each constructor function (see man page of a particular
constructor function for the details).
Coercion to List or to a List subclass. Many coercion methods are
provided to turn any object into a List object. One general and
convenient way to convert any vector-like object into a List is to
as(x, "List"). This will typically yield an object from
a subclass of CompressedList.
extractList. This function, defined
in the IRanges package, extracts user-specified groups of
elements from a vector-like object and returns them in a List (or
sometimes list) object.
In the following code snippets,
x is a List object.
Get the number of list elements in
names(x) <- value:
Get or set the names of the elements in the List.
mcols(x) <- value:
Get or set the metadata columns. See Vector man page for
Get the scalar string naming the class from which all elements must
Get the length (or nb of row for a matrix-like object) of each of
the elements. Equivalent to
Returns a logical indicating either if the sequence has no elements
or if all its elements are empty.
as(x, "List"): Converts a vector-like object into a
List, usually a CompressedList derivative.
One notable exception is when
x is an ordinary list,
in which case
as(x, "List") returns a SimpleList
To explicitly request a SimpleList derivative, call
?CompressedList (you might need to load
the IRanges package first) and
more information about the CompressedList and SimpleList
From List. In the code snippets below,
x is a List object.
x into an ordinary list.
unlist(x, recursive=TRUE, use.names=TRUE):
Concatenates the elements of
x into a single vector-like
object (of class
as.data.frame(x, row.names=NULL, optional=FALSE ,
List to a
data.frame. The result has the
same length as unlisted
x with two additional columns,
group is an
that indicates which list element the record came from.
group_name holds the list name associated with each
record; value is
character by default and
group_name.as.factor is TRUE.
use.outer.mcols is TRUE the metadata columns on the
outer list elements of
x are replicated out and included
data.frame. List objects that unlist to a
single vector (column) are given the column name 'value' by default.
A custom name can be provided in
Splitting values in the resulting
data.frame by the original
x should be done using the
group column as
f argument to
splitAsList. To relist data, use
x as the
skeleton argument to
In the code snippets below,
x is a List object.
Return a new List object made of the list elements selected by
i can be of any type supported
by subsetting of a Vector object (see Vector man page for the
details), plus the following types: IntegerList,
character-RleList, and IntegerRangesList.
Those additional types perform subsetting within the list elements
rather than across them.
x[i] <- value:
Replacement version of
Return the selected list element
i is an
numeric or character vector of length 1.
x[[i]] <- value:
Replacement version of
x$name <- value:
x[[name]] <- value, but
name is taken literally as an element name.
P. Aboyoun and H. Pagès
splitAsList for splitting a vector-like object into a List object.
List-utils for common operations on List objects.
Vector objects for the parent class.
The SimpleList class for a direct extension of the List class.
The CompressedList class defined in the IRanges package for another direct extension of the List class.
The IntegerList, RleList, and IRanges classes and constructors defined in the IRanges package for more examples of concrete List subclasses.
The extractList function defined in the IRanges package for grouping elements of a vector-like object into a list-like object.
showClass("List") # shows only the known subclasses define in this package
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’: anyDuplicated, append, as.data.frame, basename, cbind, colnames, dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep, grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank, rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply, union, unique, unsplit, which.max, which.min Attaching package: ‘S4Vectors’ The following object is masked from ‘package:base’: expand.grid Virtual Class "List" [package "S4Vectors"] Slots: Name: elementType elementMetadata metadata Class: character DataFrame_OR_NULL list Extends: Class "Vector", directly Class "list_OR_List", directly Class "Annotated", by class "Vector", distance 2 Class "vector_OR_Vector", by class "Vector", distance 2 Known Subclasses: Class "SimpleList", directly Class "TransposedDataFrame", directly Class "HitsList", by class "SimpleList", distance 2 Class "DataFrame", by class "SimpleList", distance 2 Class "SelfHitsList", by class "SimpleList", distance 3 Class "SortedByQueryHitsList", by class "SimpleList", distance 3 Class "DFrame", by class "SimpleList", distance 3 Class "SortedByQuerySelfHitsList", by class "SimpleList", distance 4 Class "FilterRules", by class "SimpleList", distance 2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.