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.
+6
A:
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.
Dirk Eddelbuettel
2010-09-12 00:18:26
AFAIK environments are the only thing that act like pointers in R. This might be a case of trying to use the wrong tool, if you are trying to use pure R.
Andrew Redd
2010-09-13 20:28:13
Dirk, I couldn't find much in the new features of R 2.12 (http://stat.ethz.ch/R-manual/R-devel/doc/html/NEWS.html) that would help. Am I missing something?
gappy
2010-09-14 01:36:15
Yes, the NEWS file is rather brief on this, see eg [refClass.Rd](http://svn.r-project.org/R/trunk/src/library/methods/man/refClass.Rd) but this is all still pretty fluid.
Dirk Eddelbuettel
2010-09-14 02:34:40
Ooh, yay. This is welcome.
Ken Williams
2010-09-15 21:08:53
A:
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.
Ken Williams
2010-09-15 16:36:12