Unlike the SimpleList class, CompressedList is virtual, that is, it cannot be instantiated. Many concrete (i.e. non-virtual) CompressedList subclasses are defined and documented in this package (e.g. CompressedIntegerList, CompressedCharacterList, CompressedRleList, etc...), as well as in other packages (e.g. GRangesList in the GenomicRanges package, GAlignmentsList in the GenomicAlignments package, etc...). It's easy for developers to extend CompressedList to create a new CompressedList subclass and there is generally very little work involved to make this new subclass fully operational.
In a CompressedList object the list elements are concatenated together in a single vector-like object. The partitioning of this single vector-like object (i.e. the information about where each original list element starts and ends) is also kept in the CompressedList object. This internal representation is generally more memory efficient than SimpleList, especially if the object has many list elements (e.g. thousands or millions). Also it makes it possible to implement many basic list operations very efficiently.
Many objects like LogicalList, IntegerList,
CharacterList, RleList, etc... exist in 2 flavors:
CompressedList and SimpleList. Each flavor is
incarnated by a concrete subclass: CompressedLogicalList and
SimpleLogicalList for virtual class LogicalList,
CompressedIntegerList and SimpleIntegerList for
virtual class IntegerList, etc...
It's easy to switch from one representation to the other with
as(x, "CompressedList") and
Also the constructor function for those virtual classes have a
switch that lets the user choose the representation at construction
CharacterList(..., compress=TRUE) or
CharacterList(..., compress=FALSE). See below for more
See the List man page in the S4Vectors package
for a quick overview of how to construct List objects in general. Unlike for SimpleList objects, there is no
CompressedList constructor function. However, many constructor functions for List objects
have a switch that lets the user choose between the CompressedList and
SimpleList representation at construction time.
For example, a CompressedCharacterList object can be constructed
All the coercions documented in the List man page apply to CompressedList objects.
Looping and functional programming
When a CompressedList object is displayed, the "Compressed" prefix is
removed from the real class name of the object.
classNameForDisplay in the S4Vectors
package for more information about this.
## Displaying a CompressedList object: x <- IntegerList(11:12, integer(0), 3:-2, compress=TRUE) class(x) ## The "Simple" prefix is removed from the real class name of the ## object: x ## This is controlled by internal helper classNameForDisplay(): classNameForDisplay(x)