[Rd] Using STL containers in R/C++
Dirk Eddelbuettel
edd at debian.org
Thu Jan 5 15:52:13 CET 2006
Andrew Finley <finle014 <at> umn.edu> writes:
> I am in the process of writing an R extension in c++ and am using several
> STL containers (e.g., vector<double>, map<int, double>, multimap<int,
> double>). I make sure to clear all these containers at the end of the
> .Call. Everything compiles and runs just fine, but I'm a bit worried
> since I haven't found any other packages that use STL.
RQuantLib, a wrapper to the QuantLib libraries, has indirect exposure to Boost.
[ QuantLib uses Boost smart pointers, and unit testing. ] However, I have kept
the actual R-to-QuantLib interface very 'plain C' to keep it simple and sane.
Dominick Samperi wrote a Rcpp.{hpp,cpp} class for C++ to R interface that is
used in RQuantLib. Dominick was musing about releasing this stand-alone to CRAN
as well, but I don't think it has happened.
> So, my question: is it OK to use the STL containers in my code? Will the
In my book, yes. It would be nice to have a few nice, and documented, examples.
> use of this library somehow limit portability of this package?
I don't see why. Effectively, R goes where gcc/g++ go so if you make sure you
stay within the bounds of g++. It will create an external dependency, as those
do confuse users from time to time (c.f. the r-help archives).
> Or cause memory management problems?
If you have a bug, yes. If you don't, you don't. The R Extensions manual has a
few tips on the matter.
Cheers, Dirk
More information about the R-devel
mailing list