| Container | R Documentation |
This class implements a container data structure with typical
member functions to insert, delete and access elements from the container.
For the standard S3 interface, see container().
This class inherits from class Iterable and serves as the base class for Deque, Set, and Dict.
container::Iterable -> Container
new()constructor
Container$new(...)
...initial elements put into the Container
the Container object
add()add element
Container$add(value, name = NULL)
valuevalue of ANY type to be added to the Container.
namecharacter optional name attribute of the value.
the Container object
at()Same as at2 (see below) but accepts a vector of
indices and always returns a Container object.
Container$at(index)
indexvector of indices.
Container object with the extracted elements.
at2()Extract value at index. If index is invalid or not found, an error is signaled. If given as a string, the element matching the name is returned. If there are two or more identical names, the value of the first match (i.e. leftmost element) is returned.
Container$at2(index)
indexMust be a single number > 0 or a string.
If given as a number, the element at the corresponding position, and if given as a string, the element at the corresponding name matching the given string is returned.
clear()delete all elements from the Container
Container$clear()
the cleared Container object
count()Count number of element occurences.
Container$count(elem)
elemelement to be counted.
integer number of elem occurences in the Container()
delete()Search for occurence(s) of elem in Container and
remove first one that is found. If elem does not exist, an error
is signaled.
Container$delete(elem)
elemelement to be removed from the Container.
the Container object
delete_at()Delete value at given index. If index is not found, an error is signaled.
Container$delete_at(index)
indexcharacter or numeric index
the Container object
discard()Search for occurence(s) of elem in Container and
remove first one that is found.
Container$discard(elem)
elemelement to be discarded from the Container. If not
found, the operation is ignored and the object is not altered.
the Container object
discard_at()Discard value at given index. If index is not found, the operation is ignored.
Container$discard_at(index)
indexcharacter or numeric index
the Container object
empty()This function is deprecated. Use is_empty() instead.
Container$empty()
get_compare_fun()Get comparison function used internally by the
Container object to compare elements.
Container$get_compare_fun()
has()Determine if Container has some element.
Container$has(elem)
elemelement to search for
TRUE if Container contains elem else FALSE
has_name()Determine if Container object contains an element
with the given name. If called with no argument, the function
determines whether any element is named.
Container$has_name(name)
namecharacter the name
TRUE if Container has the name otherwise FALSE
is_empty()Check if Container is empty
Container$is_empty()
TRUE if the Container is empty else FALSE.
length()Number of elements of the Container.
Container$length()
integer length of the Container, that is, the number of
elements it contains.
names()Names of the elements.
Container$names()
character the names of the elements contained in x
peek_at()Same as peek_at2 (see below) but accepts a vector of
indices and always returns a Container object.
Container$peek_at(index, default = NULL)
indexvector of indices.
defaultthe default value to return in case the value at
index is not found.
Container object with the extracted elements.
peek_at2()Peek at index and extract value. If index is invalid,
missing, or not not found, return default value.
Container$peek_at2(index, default = NULL)
indexnumeric or character index to be accessed.
defaultthe default value to return in case the value at
index is not found.
the value at the given index or (if not found) the given default value.
pop()Get value at index and remove it from Container.
If index is not found, raise an error.
Container$pop(index)
indexMust be a single number > 0 or a string.
If given as a number, the element at the corresponding position, and if given as a string, the element at the corresponding name matching the given string is returned.
print()Print object representation
Container$print(...)
...further arguments passed to format()
invisibly returns the Container object
rename()Rename a key in the Container. An error is signaled,
if either the old key is not in the Container or the new key results
in a name-clash with an existing key.
Container$rename(old, new)
oldcharacter name of key to be renamed.
newcharacter new key name.
the Container object
replace()Replace one element by another element.
Search for occurence of old and, if found, replace it by new.
If old does not exist, an error is signaled, unless add was
set to TRUE, in which case new is added.
Container$replace(old, new, add = FALSE)
oldelement to be replaced
newelement to be put instead of old
addlogical if TRUE the new element is added in case
old does not exists.
the Container object
replace_at()Replace value at given index.
Replace value at index by given value. If index is not found, an
error is signalled, unless add was set to TRUE, in which case
new is added.
Container$replace_at(index, value, add = FALSE)
indexcharacter or numeric index
valueANY new value to replace the old one.
addlogical if TRUE the new value element would be added
in case index did not exists.
the Container object
remove()This function is deprecated. Use delete() instead.
Container$remove(elem)
elemelement to be deleted from the Container. If element
is not found in the Container, an error is signaled.
the Container object
size()This function is deprecated. Use length() instead.
Container$size()
the Container length
type()This function is deprecated and of no real use anymore.
Container$type()
type (or mode) of internal vector containing the elements
update()Add elements of other to this if the name is
not in the Container and update elements with existing names.
Container$update(other)
otherIterable object used to update this.
returns the Container
values()Get Container values
Container$values()
elements of the container as a base list
clone()The objects of this class are cloneable with this method.
Container$clone(deep = FALSE)
deepWhether to make a deep clone.
Roman Pahl
container(), Iterable, Deque, Set, and Dict
co = Container$new(1:5, c = Container$new("a", 1), l = list())
co$print()
co$length()
co$names()
co$clear()
# Extract
co = Container$new(a = 1, b = 2, c = 3, d = 4)
co$at(1:2)
co$at(c(1, 4))
co$at(list("d", 2))
co$at2(1)
try(co$at(0:2)) # index must be > 0
co$peek_at(0:2)
co$peek_at(0:2, default = 1)
# Replace
co$replace(4, 9)
co$replace(9, 11)
co$replace_at(1, -1)
try(co$replace_at(11, 1)) # index 11 exceeds length of Container
# Delete
co$delete(-1)
co$delete_at(3)
try(co$delete_at(3)) # index 3 exceeds length of Container
co$discard(3)
co2 = Container$new(b = 0)
co2$add(0, name = "a")
co$update(co2)
co$pop(1)
co
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.