tags:

views:

108

answers:

2

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
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
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
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
Ooh, yay. This is welcome.
Ken Williams
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