Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Workaround for pointers in R?

Tags:

pointers

r

I have been implementing binary tree search algorithm recently in R, and before that I used linked array-like structures. These algorithm would be much easier if there were pointers in R (not C pointers, but references to objects). I wonder if there is a workaround. I don't know S4 at all; maybe it is possible in that framework? I would avoid environment-related tricks, since that pass-by-reference is a little too bit of a workaround. And I would avoid invocations of C or C++'s STL. It's an R question after all.

like image 461
gappy Avatar asked Sep 11 '10 23:09

gappy


2 Answers

R 2.12 will start to bring you some of this. In the meantime, the common recommendation is to use environments to approximate call-by-reference.

like image 195
Dirk Eddelbuettel Avatar answered Oct 31 '22 23:10

Dirk Eddelbuettel


You might also be interested in the binsearch() function from the genetics package: http://www.biometrics.mtu.edu/CRAN/web/packages/genetics/index.html . It implements a binary search.

like image 41
Ken Williams Avatar answered Oct 31 '22 22:10

Ken Williams