"[["
,
elementType
and elementNROWS
method.
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.
The 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
based on 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 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
a "[["
method (in addition to the minimum set of Vector
methods).
List
,IntegerList
,RleList
,RangesList
,GRangesList
, etc...
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 aconcreteclass (e.g. theGRangesList
constructor
defined in theList
constructor defined in
this package, or theIntegerList
orRleList
orRangesList
constructors defined in theas(x, "List")
. This will typically yield an object from
a subclass ofCompressedList.extractList
. This function, defined
in therelistToClass(x)
is the opposite of elementType(y)
in the
sense that the former returns the class of the result of relisting (or
splitting) x
while the latter returns the class of the result of
unlisting (or unsplitting) y
.
More formally, if x
is an object that is relistable and y
a list-like object:
relistToClass(x) is class(relist(x, some_skeleton))
elementType(y) is class(unlist(y))
As a consequence, for any object x
for which relistToClass(x)
is defined and returns a valid class,
elementType(new(relistToClass(x)))
should return class(x)
.showClass("List") # shows (some of) the known subclasses
Run the code above in your browser using DataCamp Workspace