On Dec 25, 2012, at 6:39 AM, andre__ wrote: > Hi, > > I am using swig to build a wrapper for an c-function to use it in R. I would > like to define a generic function, which gives back a void pointer. On the R > side, I know what this pointer is pointing to, whether it is an integer or > an string, or something else... but I need to somehow reinterpret the > resulting "externalptr" into another form... > > a function that looks like the following: > > *void* test(){ > std::string str="test"; > return str.c_str(); > }* > > when I call this from R: > > *str <- test() > typeof(str) % result is: "externalptr"* > > how could I reinterpret this to a charcterarray, to a numeric, to list, or > ... >
The simple answer is you can't. External pointers are entirely opaque to R, so *you* have to write that code that interprets them. Obviously it's then up to you to create the corresponding R object from the external pointer. You may want to have a look at interface packages like Rcpp, rJava, Rserve, ... to understand how objects are converted to/from other languages. Cheers, Simon > Thanks for any suggestions ;) > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/reinterpreting-externalptr-in-R-tp4653908.html > Sent from the R devel mailing list archive at Nabble.com. > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > > ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel