[Rd] Question about SET_LENGTH

From: James Bullard <bullard_at_berkeley.edu>
Date: Mon 29 Aug 2005 - 18:15:28 GMT


Hello all, thanks for all the help on the other issues. This one should be relatively straightforward. I have a vector of integers which I allocate to be the maximal size possible (meaning I'll never see more than cel.GetNumOutliers, but most likely I'll see less) therefore, I want to resize the vector, one solution would be to allocate a new vector then to copy into the new vector. That is what I was going to do until I saw the SET_LENGTH macro. Does this macro effectively take care of the memory? Is this an acceptable use of the macro? The code works, but I dont want any lurking memory problems.

PROTECT(outliers = NEW_INTEGER(cel.GetNumOutliers()));

 if (i_readOutliers != 0) {

     if (noutlier == 0) {
        outliers = R_NilValue;

}
else if (noutlier < cel.GetNumOutliers()) { SET_LENGTH(outliers, noutlier);
}

 }

Thanks as always!

jim



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue Aug 30 04:20:33 2005

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:19 GMT