Learn R Programming

cppcontainers (version 1.0.4)

insert_or_assign: Add or overwrite elements

Description

Add elements to a container by reference. Overwrites existing container values tied to the same keys.

Usage

insert_or_assign(x, values, keys)

Value

Invisibly returns NULL.

Arguments

x

A CppMap or CppUnorderedMap object.

values

Values to add to x.

keys

Keys to add to x.

Details

Use insert to avoid overwriting values.

See Also

insert, insert_after, emplace, try_emplace.

Examples

Run this code
m <- cpp_map(4:6, 9:11)
m
# [4,9] [5,10] [6,11]

insert_or_assign(m, 12:13, 6:7)
m
# [4,9] [5,10] [6,12] [7,13]

Run the code above in your browser using DataLab