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
with CharacterList(..., compress=TRUE)
.?`List-utils`
in the S4Vectors package
for more information.classNameForDisplay
in the S4Vectors
package for more information about this.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 as(x, "SimpleList")
.
Also the constructor function for those virtual classes have a
switch that lets the user choose the representation at construction
time e.g. CharacterList(..., compress=TRUE)
or
CharacterList(..., compress=FALSE)
. See below for more
information.
## 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)
Run the code above in your browser using DataLab