Hi,

Please consider the following code:

a <- seq.int(10)  # create a
tracemem(a)
a[1:4] <- 4:1   # no internal copy
b <- a          # no internal copy
b[1:4] <- 1:4   # copy, b is not a any more
a[1:4] <- 1:4   # copy, but why?

With results:
> a <- seq.int(10)
> tracemem(a)
[1] "<0x1792bc0>"
> a[1:4] <- 4:1
> b <- a
> b[1:4] <- 1:4
tracemem[0x1792bc0 -> 0x1792b58]:
> a[1:4] <- 1:4
tracemem[0x1792bc0 -> 0x1792af0]:


##

Could you provide a brief explanation or point me to a source why R needs a copy in the final step?


Best,
  Denes



> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to