external pointers
Patrick,
On Dec 28, 2011, at 12:07 AM, Patrick Leyshock wrote:
I have an external pointer object that I'd like to pass from my R code to
some C code. Per Section 5.13 of "Writing R Extensions", I've noted that
"external pointers should only be used as part of an object with normal
semantics, for example an attribute or an element of a list." So I've
written up a workable C function as such:
SEXP my_c_function(SEXP param) {
SEXP temp = getAttrib(param, install("ptr_attribute"));
void * ptr = R_ExternalPtrAddr(temp);
... // do useful things with ptr
}
I can pass my_c_function() an object with "normal" semantics (such as an
integer vector), where the external pointer object is a parameter named
"ptr_attribute". The function extracts the pointer object from param; i.e.
this function does what I want it to do.
My question is: is there a way to do this using the .C() interface, rather
than .Call()?
No. Why would you want to do that? .C is slower and mostly for backwards-compatibility. You can't pass anything complex with .C and the docs recommend .Call for this. The whole point of .C was to bypass R API but in your case you need it to get the pointer.
Using call_R seems a possibility - has anyone had luck going this route?
call_R has nothing to do with this, it is sort of the equivalent of using the restricted set of objects to evaluate R function (so you still can't pass your pointer). As the docs say there is no point in using it in modern code. Cheers, Simon
Any suggestions appreciated. Thanks, Patrick [[alternative HTML version deleted]]
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel