[Rd] Use of Rf_duplicate

From: Michael Braun <braunm_at_MIT.EDU>
Date: Tue, 29 May 2007 09:31:35 -0400


First, thanks to those of you who responded to my previous post about my code that was taking longer and longer to process. After following your suggestions, and I now thinking that the problem was some calls to Rf_duplicate in my C code.

So I'm hoping I could get some clarification on what Rf_duplicate actually does. What is the real difference between

PROTECT(y=x); and
PROTECT (y = duplicate(x)); ?

I do use duplicate on the list objects that are passed directly from R, since in the passed, I got some odd results of the original lists being changed (when I didn't want them to be). So suppose that x is the list that is passed from R to the C code. Is there any (conceivable) reason that I might want to do something like

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

Instead of

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

And if I did create a duplicate, is there a way to destroy it manually before the end of the function, rather than rely on on the R garbage collector?

Thanks,

Michael

Michael Braun
Assistant Professor of Marketing
MIT Sloan School of Management
One Amherst St., E40-169
Cambridge, MA 02142
(617) 253-3436
braunm_at_mit.edu

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 29 May 2007 - 13:40:01 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 30 May 2007 - 00:34:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.