Dict {container}R Documentation

Dict Class

Description

The Dict() resembles Python's dict type, and is implemented as a specialized associative Container(). For the standard S3 interface, see dict().

Details

This class inherits from class Container() and overwrides some methods to account for the associative key-value pair semantic. Internally, all key-value pairs are stored in a hash-table and the elements are always sorted lexicographically by their keys.

Super classes

container::Iterable -> container::Container -> Dict

Methods

Public methods

Inherited methods

Method new()

Dict constructor

Usage
Dict$new(...)
Arguments
...

initial elements put into the Dict

Returns

returns the Dict


Method add()

If name not yet in Dict, insert value at name, otherwise signal an error.

Usage
Dict$add(name, value)
Arguments
name

character variable name under which to store value.

value

the value to be added to the Dict.

Returns

the Dict object


Method discard_at()

Discard value at given index. If index is not found, the operation is ignored.

Usage
Dict$discard_at(index)
Arguments
index

character or numeric index

Returns

the Dict object


Method get()

This function is deprecated. Use at2() instead.

Usage
Dict$get(key)
Arguments
key

character name of key.

Returns

If key in Dict, return value at key, else throw error.


Method keys()

Get all keys.

Usage
Dict$keys()
Returns

character vector of all keys.


Method remove()

This function is deprecated. Use delete() instead.

Usage
Dict$remove(key)
Arguments
key

character name of key.

Returns

If key in Dict, remove it, otherwise raise an error.


Method 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.

Usage
Dict$replace(old, new)
Arguments
old

element to be replaced

new

element to be put instead of old

Returns

the Dict object


Method set()

This function is deprecated. Use replace() instead.

Usage
Dict$set(key, value, add = FALSE)
Arguments
key

character name of key.

value

the value to be set

add

logical if TRUE the value is set regardless whether key already exists in Dict.

Returns

returns the Dict


Method sort()

Sort elements according to their keys. This function is deprecated as keys are now always sorted.

Usage
Dict$sort(decr = FALSE)
Arguments
decr

logical if TRUE sort in decreasing order.

Returns

returns the Dict


Method update()

Add elements of other to this if the name is not in the Dict and update elements with existing names.

Usage
Dict$update(other)
Arguments
other

Iterable object used to update this.

Returns

returns the updated Dict object.


Method values()

Get Container values

Usage
Dict$values()
Returns

a copy of all elements in a list


Method clone()

The objects of this class are cloneable with this method.

Usage
Dict$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Container(), dict()

Examples

d = Dict$new(o = "one", na = NA, a = 1)
d
d$keys()

d$add("li", list(1, 2))
d$discard_at("na")
d$replace(1, 9)

d2 = Dict$new(a = 0, b = 1)
d$update(d2)

[Package container version 1.0.4 Index]