Skip to content

Function arguments and copying objects

2 messages · Giovanni Petris, Brian Ripley

#
I have a function that, via .Call, modifies its argument, so I first
create a backup copy of the object I want to pass, make a copy of it,
and pass the copy to the function. However, my function also modifies
the backup copy. I guess this has to do with R not duplicating objects
until they are modified. Where can I read more about that? And/or how
can I solve my problem, i.e. save a copy of the argument?

Here is an example of what I mean:
$m0
[1] -0.03431583 -1.66513535

...
$m0
[1] 3.360737 3.266844

...


Thanks in advance,
Giovanni
#
R-devel is the appropriate place for C programming questions: please DO 
read the posting guide.

You need to check the NAMED flag and call duplicated as necessary.
There are many examples in src/main/*.c.
On Tue, 10 May 2005, Giovanni Petris wrote: