Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic documentation for Rcpp

Tags:

r

rcpp

I want to look into rcpp to improve the speed of some of my R code without having to resort to messy C++ code (I've had some success with that, but it looks like code from hell).

So, I checked the documentation provided with Rcpp, and also the bundle of documents provided at Dirk Eddelbuettel's site. I installed and looked at RcppExamples, but (at least from its documentation) most of these refer to RcppClassic?. Besides that, I did some googling but that didn't result in answers to what seem like basic questions.

  • Do indexes in Rcpp work zero-based or one-based
  • List provides both operator() and operator[], but apparently not operator[[]]. It is not clear which ones are similar to [] and [[]] in R.
  • Is there any support for factors in Rcpp (there does not appear to be any)?

Note: in fact I found some answers from the first example in Rcpp-introduction.pdf, but that just felt like luck.

Also, my stl is very rusty, so if anybody can provide me with a simple example where each element of a List is (e.g.) print-ed with an stl-style loop, that would be neat.

If anybody wants to call me an idiot for not finding this information: go ahead and make your day. Then make mine and point me to the docs I need :-)

As a suggestions to Mr. Eddelbuettel and other Rcpp authors (I expect some of them to read this): the class hierarchies and the like, provided by doxygen, are really neat when you are already kneedeep into Rcpp, but for a beginner (in Rcpp), I am more interested in a list of 'this method in this class does this like that function in R' rather than 'you can find the declaration of this operator in this header file'. After all, I understand one of the goals of Rcpp is to lower the threshold for using C++ in R? Note: from what I have seen and understood, I highly value the actual code of Rcpp and have the highest respect for its creators. If the lack of basic documentation is merely a result of 'lack of resources', I would be willing to become a resource (e.g.: work on 'basic' documentation once I get through it myself).

like image 582
Nick Sabbe Avatar asked May 13 '11 11:05

Nick Sabbe


People also ask

What is RCPP?

The Regional Conservation Partnership Program (RCPP), established through the 2014 Farm Bill, allows conservation partners with similar missions to collaborate with USDA's Natural Resources Conservation Service (NRCS) to further the conservation, restoration, and sustainable use of soil, water, and wildlife habitat in ...

What is RCPP sugar?

Rcpp sugar brings a higher-level of abstraction to C++ code written using the Rcpp API. Rcpp sugar is based on expression templates (Abrahams and Gurtovoy, 2004; Vandevoorde and Josuttis, 2003) and provides some 'syntactic sugar' facilities directly in Rcpp.


1 Answers

I do not quite know where to start answering this but here is a quick attempt:

  • The package has a website. The website lists the documentation.

  • The package has eight (8) vignettes. They are clearly listed. They are mostly meant to be read as documentation, some more introductory and some more advanced. Some (such as the unit testing output) are more of a quality-control iniative.

  • There is a vignette called Rcpp-introduction. We refer to it repeatedly. We suggest you read it. This is now also a peer-reviewed and published paper which may lend it even more credibility.

  • There is a vignette called Rcpp-FAQ. It's first question is "How do I get started?" which points to the aforementioned Rcpp-introduction.

  • There is a mailing list dedicated to project, you could actually read the archive.

  • We have given numerous talks, slides are available as is a 90 minute recording of a Google Tech Talk.

  • Even StackOverflow has a tag for it: [rcpp]. You could read the earlier posts.

  • There are over two dozen packages clearly listed on the CRAN page for Rcpp as using it. You could read their source code.

All that said, Rcpp cannot be used instead of C++ so if you do not know or understand that operator[[]] cannot exist in C++ we cannot help you either. This is not a magic fairy, or R-to-C++ code compiler. Rather, its focus is to make it much easier to get to C++ code from R, and in some cases even manages to improve on C++ practice. In essence, it tries to be "super-additive": the combination R and C++ should be more than either in isolation.

Lastly, I do grant you that the RcppExamples packages -- which by the way covers the old and new API -- could use more examples. However, its sourecs give good porting hints from old ("classic") to the new and current API.

But there is only so much documentation we can write ourselves. I myself find the above bullet points quite exhaustive. You may have honed in on the weakest element part of the chain though. That is bad luck. Please do try some of other pointers listed here.

like image 80
Dirk Eddelbuettel Avatar answered Oct 02 '22 20:10

Dirk Eddelbuettel