[R] Function arguments and copying objects

Giovanni Petris GPetris at uark.edu
Tue May 10 20:10:40 CEST 2005


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:

> mod.back$m0 <- rnorm(2)
> mod.back
$m0
[1] -0.03431583 -1.66513535

...

> mod <- mod.back
> dlmLLsvd(ip,mod)
> mod.back
$m0
[1] 3.360737 3.266844

...


Thanks in advance,
Giovanni

-- 

 __________________________________________________
[                                                  ]
[ Giovanni Petris                 GPetris at uark.edu ]
[ Department of Mathematical Sciences              ]
[ University of Arkansas - Fayetteville, AR 72701  ]
[ Ph: (479) 575-6324, 575-8630 (fax)               ]
[ http://definetti.uark.edu/~gpetris/              ]
[__________________________________________________]




More information about the R-help mailing list