Get object at memory address

I am trying to find ways to make a list of links in R.

I found that it tracemem()returns the memory address of the object, so is there a way to find the object by its memory address?

+5
source share
1 answer

This is not a way to do this. If you want links to use Reference Classes or environments. Like this:

Firstly, there are three objects that I am going to put in a linked list:

> e1=new.env()
> e2=new.env()
> e3=new.env()

initialize the data item and a pointer to the next one in the list

> with(e1,{data=99;nextElem=e2})
> with(e2,{data=100;nextElem=e3})
> with(e3,{data=1011;nextElem=NA})

Now the function defining the environment returns the following in a linked list:

> nextElem = function(e){with(e,nextElem)}

So, let's start with some environment e:

> e=e1
> with(e,data)
[1] 99

To get the value of the following item in the list:

> with(nextElem(e),data)
[1] 100

, , e2:

> with(e2,{data=555})

e :

> with(nextElem(e),data)
[1] 555

, .

R .

+5

Source: https://habr.com/ru/post/1613820/


All Articles