Deep copy warning

edit: Actually, I don’t get that warning with codes below, I could have sworn that I got before… See below.

I was just wondering the same thing. Simplest case where we get this warning is when doing something like

for(t in 1:10) {
  x[t+1] = x[t];
}

If you just want to get rid of the warning, you could use temporaries yourself:

for(t in 1:10) {
  tmp = x[t];
  x[t+1] = tmp;
}

But whether this is clever in terms of efficiency, I don’t know. The warning suggests that that is what is happening anyway. Or not, is there are a deep copy of the whole vector of x at each iteration or just copying of the subset like in above manual copying?

EDIT: The codes above do not actually trigger the warning, but this does:

for(t in 1:(n-1)) {
  x[, t+1] = x[, t];
}

whereas this does not:

for(t in 1:(n-1)) {
  x[1, t+1] = x[1, t];
}