[Rd] Array changing address unexpectedly

lille stor lille.stor at gmx.com
Sun Nov 12 17:47:37 CET 2017


Hi,

Given the following R code:

     library(pryr)

     data <- array(dim = c(5))

     for(x in 1:5)
     {
          data[x] <- as.integer(x * 2)
     }

     add = address(data) # save address of "data"

     for(x in 1:5)
     {
          data[x] <- as.integer(0)
     }

     if (add == address(data))
     {
        print("Address did not change")
     }
     else
     {
        print("Address changed")
     }

If one runs this code, message "Address changed" is printed. However, if one comments line "data[x] <- as.integer(0)" the address of "data" does not change and message "Address did not change" is printed instead. Why? The datatype of the array should not change with this line and hence no need for R to convert the array to a different type (and have the array's address changing in the process).
 
Thank you!



More information about the R-devel mailing list