From lille.stor at gmx.com  Sun Nov 12 17:47:37 2017
From: lille.stor at gmx.com (lille stor)
Date: Sun, 12 Nov 2017 17:47:37 +0100
Subject: [Rd] Array changing address unexpectedly
Message-ID: <trinity-72a45fb5-062c-4f24-9082-4069285db083-1510505257888@3c-app-mailcom-bs15>

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!



[Rd] Array changing address unexpectedly
lille stor