On Apr 18, 2009, at 4:12 AM, whizvast wrote:
Hi, I am a newbie on C++
Right now I have an array of doubles in C++.
Is there a way to "export" that array into R? Of course, I can
allocate
the memory block first using "allocVector" and copying the array
contents
one by one.
But, what if that array is fairly large? Copying doesn't look that
efficient.
I was thinking of setting the data pointer(DATAPTR) point to that
array,
and adjust the LENGTH of SEXP. But I don't know how to do that.
The short answer is no, you can't, because the memory has to be
allocated by R. If you are allocating the memory yourself, you can
simply use allocVector instead of malloc/new to allocate the array in
the first place - that saves you the copying and is the more usual
approach for such R packages.
Cheers,
Simon
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel