Creates a true copy of the underlying C-vector – dropping all attributes – and optionally reverses the direction of the elements.

copy_vector(x, revx = FALSE)

Arguments

x

an R vector

revx

default FALSE, set to TRUE to reverse the elements in 'x'

Value

copied R vector

Details

This can be substantially faster than duplicate(as.vector(unclass(x)))

Examples

x <- factor(letters)
y <- x
z <- copy_vector(x)
still.identical(x, y)
#> [1] TRUE
still.identical(x, z)
#> [1] FALSE
str(x)
#>  Factor w/ 26 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10 ...
str(y)
#>  Factor w/ 26 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10 ...
str(z)
#>  int [1:26] 1 2 3 4 5 6 7 8 9 10 ...