Skip to content
Prev 15775 / 63461 Next

dynamic array output by .C

On Thu, 14 Apr 2005, Simon Urbanek wrote:

            
That's not a particularly good idea, as R keeps the length in the vector.
There is a way to do this, lengthgets().  That shortens vectors in one 
case, and reallocates and copies contents if extending.  Quite a lot of 
internal code does use long vectors and call lengthgets() at the end to 
shorten them to the right size.  (Other code duplicates that in 
lengthgets.)

As the name implies, this is the internal form of length(x) <- value.

Yes, it does change the pointer because it creates (potentially a new 
object).  But since an R object is just a few parameters (e.g. type and 
length) and a pointer, you could in fact extend an R vector `in place'.