Re: [Rd] Is it possible to shrink an R object in place?

2014-04-11 Thread Simon Urbanek
On Apr 11, 2014, at 3:47 PM, Romain Francois wrote: > Hello, > > I’ve been using shrinking in > https://github.com/hadley/dplyr/blob/master/inst/include/tools/ShrinkableVector.h > > This defines a ShrinkableVector of some R type (INTSXP, ...) given the > maximum number of elements it will h

Re: [Rd] Is it possible to shrink an R object in place?

2014-04-11 Thread Romain Francois
Hello, I’ve been using shrinking in https://github.com/hadley/dplyr/blob/master/inst/include/tools/ShrinkableVector.h This defines a ShrinkableVector of some R type (INTSXP, ...) given the maximum number of elements it will hold. Then, I reset with SETLENGTH when needed. The constructor prote

Re: [Rd] Is it possible to shrink an R object in place?

2014-04-11 Thread Simon Urbanek
Kevin, Kevin, On Apr 10, 2014, at 4:57 PM, Kevin Ushey wrote: > Suppose I generate an integer vector with e.g. > >SEXP iv = PROTECT(allocVector(INTSXP, 100)); > > and later want to shrink the object, e.g. > >shrink(iv, 50); > > would simply re-set the length to 50, and allow R to rec

[Rd] Is it possible to shrink an R object in place?

2014-04-10 Thread Kevin Ushey
Suppose I generate an integer vector with e.g. SEXP iv = PROTECT(allocVector(INTSXP, 100)); and later want to shrink the object, e.g. shrink(iv, 50); would simply re-set the length to 50, and allow R to reclaim the memory that was previously used. Is it possible to do this while respec