Last active
February 22, 2024 16:22
-
-
Save alekrutkowski/c14669c80523ca279dff3623fca53ee7 to your computer and use it in GitHub Desktop.
Get memory address of an R object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
memoryAddress <- function(x) | |
strsplit(capture.output(.Internal(inspect(x))),split=" ")[[1]][1] | |
### Usage examples | |
# > abc <- c(1,2,3,10,11) | |
# > xyz <- abc | |
# > memoryAddress(abc)==memoryAddress(xyz) | |
# [1] TRUE | |
# > xyz <- abc+1 | |
# > memoryAddress(abc)==memoryAddress(xyz) | |
# [1] FALSE | |
# > abc <- c(1,2,3,10,11) | |
# > xyz <- abc | |
# > memoryAddress(abc)==memoryAddress(xyz) | |
# [1] TRUE | |
# > xyz <- unserialize(serialize(abc,NULL)) # "deep copy" hack | |
# > memoryAddress(abc)==memoryAddress(xyz) | |
# [1] FALSE | |
# > identical(abc,xyz) | |
# [1] TRUE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment