Learn R Programming

lvec (version 0.2.5)

clone: Clone an lvec object

Description

Clone an lvec object

Usage

clone(x, ...)

# S3 method for lvec clone(x, ...)

Arguments

x

lvec object to clone

...

ignored; used to pass additional arguments to other methods

Details

lvec objects are basically pointers to pieces of memory. When copying an object only the pointer is copied and when modifying the copied object also the original object is modified. The advantage of this is speed: these is less copying of the complete vector. In order to obtain a true copy of an lvec code can be used.

Examples

Run this code
a <- as_lvec(1:3)
# Copy
b <- a
# When modifying the copy also the original is modified
lset(b, 1, 10)
print(a)
print(b)
# Use clone to make a true copy
b <- clone(a)
lset(b, 1, 100)
print(a)
print(b)

Run the code above in your browser using DataLab