Learn R Programming

cppcontainers (version 1.0.4)

insert: Add elements

Description

Add elements to a container by reference.

Usage

insert(x, values, keys = NULL, position = NULL)

Value

Invisibly returns NULL.

Arguments

x

A CppSet, CppUnorderedSet, CppMultiset, CppUnorderedMultiset, CppMap, CppUnorderedMap, CppMultimap, CppUnorderedMultimap, CppVector, CppDeque, or CppList object.

values

Values to add to x.

keys

Keys to add to x. Only relevant for CppMap, CppUnorderedMap, CppMultimap, and CppUnorderedMultimap objects.

position

Index at which to insert elements into x. Only relevant for CppVector, CppDeque, and CppList objects. Indices start at 1.

Details

Existing container values are not overwritten. I.e. inserting a key-value pair into a map that already contains that key preserves the old value and discards the new one. Use insert_or_assign to overwrite values.

See Also

assign, emplace, insert_after, insert_or_assign, push.

Examples

Run this code
s <- cpp_multiset(4:6)
s
# 4 5 6

insert(s, 6:7)
s
# 4 5 6 6 7

m <- cpp_map(c("hello", "there", "world"), 9:11)
m
# ["hello",9] ["there",10] ["world",11]

insert(m, 12L, "there")
m
# ["hello",9] ["there",10] ["world",11]

Run the code above in your browser using DataLab