Don’t bother using the container
framework if
speed is of high importance. An exception is the
dict.table
class, which is very fast as it is based on data.table.
Other than that, if computation speed is critical for your application,
we refer you to using base R list or packages that were
optimized for performance, such as the collections
package.
Consider using the container
framework over base
list
if you are looking for …
Furthermore consider using dict.table
for a flexible and
robust way to manage data columns
of data.table
s.
In an interactive R session a container
can be used
similar to a base R list
, but also provides some extra
features. For easier typing it’s recommended to use the shorter
cont
.
The container print method is designed to be very compact.
For more verbose output, either convert to a base list
…
or use str
.
Both length
and names
work as usual.
A container can also be constructed from a list.
Elements can be added by concatenation,
or name,
and containers can be nested.
In contrast to base R list
, elements cannot be added via
positional index if it exceeds the container’s length.
Single or multiple value replacement works as usual.
In contrast to base list
, containers can take a mix of
numeric and character indices.
co[list("A", 2, "c")] <- list(1, 2, "three")
co
# [A = 1, b = 2, c = "three", co2 = [x = (1 2), y = (1 4)]]
Another option for container object is to replace by value.
This works for any data type.
The standard operators to access elements also should be familiar to R users. 1
As another option, you can pass any number of indices, possibly mixed as numeric and character.
Invalid indices don’t produce NULL
s but are just
ignored.
Next, see vignette Container operations for robust code.
Note that the $
operator does not work.↩︎