Re: [Rd] Basic Question regarding PROTECT

2009-08-24 Thread Thomas Lumley
On Mon, 24 Aug 2009, Saptarshi Guha wrote: > Thank you. So the reason I wouldnt need to protect y had I returned to > R, is because had i had done something like > > h<-.Call("boo",a) > where "boo" contains y=foo() > > the assignment "<-" to h would have a PROTECT somewhere, i.e R's > assignment

Re: [Rd] Basic Question regarding PROTECT

2009-08-24 Thread Saptarshi Guha
Oh! Yes, this is the GC at work, "root objects" and everything referenced from them. I think I'm understanding the need for PROTECT better. Thank you Saptarshi On Mon, Aug 24, 2009 at 9:39 AM, Duncan Murdoch wrote: > On 8/24/2009 9:33 AM, Saptarshi Guha wrote: >> >> Thank you. So the reason I wo

Re: [Rd] Basic Question regarding PROTECT

2009-08-24 Thread Duncan Murdoch
On 8/24/2009 9:33 AM, Saptarshi Guha wrote: Thank you. So the reason I wouldnt need to protect y had I returned to R, is because had i had done something like h<-.Call("boo",a) where "boo" contains y=foo() the assignment "<-" to h would have a PROTECT somewhere, i.e R's assignment is doing the

Re: [Rd] Basic Question regarding PROTECT

2009-08-24 Thread Saptarshi Guha
Thank you. So the reason I wouldnt need to protect y had I returned to R, is because had i had done something like h<-.Call("boo",a) where "boo" contains y=foo() the assignment "<-" to h would have a PROTECT somewhere, i.e R's assignment is doing the protection for me. Had I not returned to R, I

Re: [Rd] Basic Question regarding PROTECT

2009-08-24 Thread Duncan Murdoch
On 8/24/2009 9:10 AM, Sapsi wrote: Hello Thank you for the response. So if my call is y=foo() z=malloc ( by memory allocations , do you mean via R_alloc and allocVector and malloc or just the former two) Any allocation which is managed by R's memory manager, so that includes the former two,

Re: [Rd] Basic Question regarding PROTECT

2009-08-24 Thread Sapsi
Hello Thank you for the response. So if my call is y=foo() z=malloc ( by memory allocations , do you mean via R_alloc and allocVector and malloc or just the former two) Other statements Then I need to protect y. And in my case I don't return to R since I have embedded it. Why is this the

Re: [Rd] Basic Question regarding PROTECT

2009-08-24 Thread Duncan Murdoch
On 8/23/2009 11:52 PM, Saptarshi Guha wrote: Hello, Suppose I have the function SEXP foo(){ SEXP s; PROTECT(s=allocVector(...)) UNPROTECT(1); return(s) } y=foo() // foo is a recusrive call Q: Am i correct in understanding that one does not need to write PROTECT(y=foo()) ?(and a correspond

[Rd] Basic Question regarding PROTECT

2009-08-23 Thread Saptarshi Guha
Hello, Suppose I have the function SEXP foo(){ SEXP s; PROTECT(s=allocVector(...)) UNPROTECT(1); return(s) } y=foo() // foo is a recusrive call Q: Am i correct in understanding that one does not need to write PROTECT(y=foo()) ?(and a corresponding unprotect later on) since it is the object