[R] .C and 'temporaries'
murdoch at stats.uwo.ca
Wed Dec 24 01:52:15 CET 2008
On 23/12/2008 6:55 PM, Thomas Mang wrote:
> Before I get into troubles I ask here:
> I make a call to a C function using .C. What I would like to know is if
> the arguments in the .C call can also be 'temporary' objects.
> An example will illustrate this:
> # here we don't have a temporary
> Obj1 = 5
> .C("Func", as.integer(Obj1 ), ...) # certainly works
> # here we do have a temporary
> Obj2 = 5
> .C("Func", as.integer(Obj2 + 100), ...) # is this guaranteed to work?
> Is the second call valid?
Yes. It makes a copy of the object computed as Obj2 + 100, and passes
that to Func.
> Is it also valid if DUP = FALSE, or only if DUP = TRUE ?
I suspect it is, but I would never use DUP = FALSE. What the docs say
is that this will let you modify the temporary object Obj2 + 100, and
then the results will be returned in the return value of .C. So it
should be safe, but it is probably not tested very frequently. If you
are worried about the overhead of duplicating the vector, it's probably
time to learn the .Call interface instead.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help