HenrikBengtsson / Wishlist-for-R

Features and tweaks to R that I and others would love to see - feel free to add yours!
https://github.com/HenrikBengtsson/Wishlist-for-R/issues
GNU Lesser General Public License v3.0
134 stars 4 forks source link

R C API for efficient pop and push methods #99

Open jangorecki opened 5 years ago

jangorecki commented 5 years ago

The wish item is about API for efficient pop and push methods, that operates in-place. Because R is a functional language I understand it might not provide such methods directly. Still it makes perfect sense to provide R C API for developers who needs efficient in-place pop and push methods, to avoid memcpy, memmove or R-level copies. It is important for R to not lag behind other languages, as pop/push methods are pretty fundamental element of many systems. As of now SETLENGTH and SET_TRUELENGTH are not part of public API, and AFAIU won't fully address the request. I recall a grow-able vectors in recent R development, maybe that would be proper place for formulating such API. Some related SO: https://stackoverflow.com/questions/57334741/subsetting-a-large-vector-uses-unnecessarily-large-amounts-of-memory https://stackoverflow.com/questions/2778510/efficiently-adding-or-removing-elements-to-a-vector-or-list-in-r

tdhock commented 4 years ago

this is possible via Rcpp modules https://cloud.r-project.org/web/packages/Rcpp/vignettes/Rcpp-modules.pdf (and in fact the vignette has an example showing how to do that)

jangorecki commented 4 years ago

And what about C?