Dear list members, I was wondering why R is making a copy-on-modification after using str.
m <- matrix(1:12, 3) tracemem(m) #[1] "<0x559df861af28>" dim(m) <- 4:3 m[1,1] <- 0L m[] <- 12:1 str(m) # int [1:4, 1:3] 12 11 10 9 8 7 6 5 4 3 ... dim(m) <- 3:4 #Here after str a copy is made #tracemem[0x559df861af28 -> 0x559df838e4a8]: dim(m) <- 3:4 str(m) # int [1:3, 1:4] 12 11 10 9 8 7 6 5 4 3 ... dim(m) <- 3:4 #Here again after str a copy #tracemem[0x559df838e4a8 -> 0x559df82c9d78]: Also I was wondering why a copy is made when having a Task Callback. TCB <- addTaskCallback(function(...) TRUE) m <- matrix(1:12, nrow = 3) tracemem(m) #[1] "<0x559dfa79def8>" dim(m) <- 4:3 #Copy on modification #tracemem[0x559dfa79def8 -> 0x559dfa8998e8]: removeTaskCallback(TCB) #[1] TRUE dim(m) <- 4:3 #No copy I am using R version 4.0.3. Kind regards, Georg ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.