[R] C++: Appending Values onto an R-Vector.

Jim Java jjava at priscian.com
Fri Dec 12 10:36:58 CET 2003


Hi folks. I posted this question a few days ago, but maybe it got lost
because of the code I included with it. I'm having a problem using the
SET_LENGTH() macro in an R extension I'm writing in C++. In a function
within the extension I use SET_LENGTH() to resize R vectors so as to
allow the concatenation of single values onto the vectors -- it's a
"push back" function to append values onto the end of a vector.
However, when I use this function to push back a large number of
values one at a time, Rgui.exe (I'm working with R 1.8.1 in Windows
XP) crashes from an Access Violation; if, however, I pre-allocate
space (is the space actually pre-allocated?) for the vector (say with
NEW_INTEGER(n) rather than NEW_INTEGER(0)) and insert values into the
allocated slots, the code works fine. If you'd like to see some test
code, I've already posted it here:

https://www.stat.math.ethz.ch/pipermail/r-help/2003-December/041871.html

Here's my question, then: Is SET_LENGTH() the appropriate way to
create space for tacking values onto the end of an R-vector in C++, or
should I be trying to tack them on in some other way?

Thanks again!

 -- Jim Java




More information about the R-help mailing list