clone: Clone an lvec object

Description Usage Arguments Details Examples

View source: R/clone.R

Description

Clone an lvec object

Usage

1
2
3
4
clone(x, ...)

## S3 method for class '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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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)

djvanderlaan/lvec documentation built on Aug. 16, 2018, 11:02 a.m.