[R] Replace is leaking?

Zhou Fang zhou.zfang at gmail.com
Thu May 28 02:36:13 CEST 2009


Okay, someone explain this behaviour to me:

Browse[1]> replace(rep(0, 4000), temp1[12] , temp2[12])[3925]
[1] 0.4462404
Browse[1]> temp1[12]
[1] 3926
Browse[1]> temp2[12]
[1] 0.4462404
Browse[1]> replace(rep(0, 4000), 3926 , temp2[12])[3925]
[1] 0

For some reason, R seems to shift indices along when doing this replacement.

Has anyone encountered this bug before? It seems to crop up from time
to time, seemingly at random. Any idea for a fix? Reassigning the
variables seems to preserve the magicness of the numbers. It all seems
very bizarre and worrying.

If anyone is interested in a R workspace to reproduce this, email me.
This is running in R 2.9.

Zhou Fang




More information about the R-help mailing list