Skip to content
Prev 25204 / 63424 Next

Use of Rf_duplicate

This has no sense as y is just the same pointer as x. By doing this you 
did not create any new data, if you modify y, x will be modified. y does 
not need protection as x is probably protected.
This will allocate new memory for data in x and copy data over there. 
This is correct, modifying y will not modify x. And y needs protection 
as it is newly allocated.
It is not clear what you want to achieve by this. z will not be part of 
y any more
The correct way would be

PROTECT(y=duplicate(x));
z = VECTOR_ELT(y,2);

as you do not need to protect z, it is done by protecting y
Not that I know about.

Best,
Oleg