r-lib / vctrs

Generic programming with typed R vectors
https://vctrs.r-lib.org
Other
289 stars 66 forks source link

vec_slice<- for POSIXlt does not clone #1951

Open antalk2 opened 3 months ago

antalk2 commented 3 months ago

For a POSIXlt vector x0

After x <- x0
vec_slice(x,1) <- another
does not only change the value of x,
it also changes the value of x0 . Is this expected?

library(vctrs)

# `[<-` works as expected (clones x)

x0_reference <- as.POSIXlt("2020-11-01")
x0           <- as.POSIXlt("2020-11-01")
another      <- as.POSIXlt("9020-11-01")
x <- x0

x[1] <- another
identical(x0, x0_reference) # TRUE
identical(x , x0          ) # FALSE

#
# `vec_slice<-` does not clone
#

x0_reference <- as.POSIXlt("2020-11-01")
x0           <- as.POSIXlt("2020-11-01")
another      <- as.POSIXlt("9020-11-01")
x <- x0

vec_is(x) # TRUE

vec_slice(x,1) <- another # also changes x0

identical(x0, x0_reference) # FALSE
identical(x , x0          ) # TRUE