29

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).

Community
  • 1
  • 1
Nick Sabbe
  • 11,684
  • 1
  • 43
  • 57
  • indexes are zero based. This one though is easy to find out by writing simple code. – mpiktas May 13 '11 at 12:45
  • 2
    You will probably get faster answers by posting to the [Rcpp-devel mailing list](https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel). – Joshua Ulrich May 13 '11 at 12:46
  • @mpiktas: I agree. This is the part I did find from the first example in Rcpp-introduction. The point is: I shouldn't have to, as the whole point of Rcpp is probably to lower the bar. I'm struggling heavily to find out what is and is not in Rcpp (lists? factors? data.frames?) @Joshua: I'll repost there. – Nick Sabbe May 13 '11 at 12:54
  • hm I thought the whole point of Rcpp is speed and convenience for those who know R and C++ very well. Documentation could be better, but that is usually the case for open source projects. – mpiktas May 13 '11 at 13:03
  • quick search in this [document](http://dirk.eddelbuettel.com/code/rcpp/Rcpp-unitTests.pdf) suggests that lists and data.frames are supported. – mpiktas May 13 '11 at 13:04
  • Have you read the Rcpp chapter from Hadley Wickham's "Advanced R" : http://adv-r.had.co.nz/Rcpp.html – Matti Pastell Apr 01 '15 at 07:23

1 Answers1

21

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.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • 9
    As I mentioned in my question, I've checked the first four bullets and came up empty. Apparently, googling (with my search terms, including rcpp) does not bring me to the mailing list archives. Even then, the mailing lists and similar are no _replacement_ for documentation (which, as I also indicated, I am willing to start writing myself, if I ever get through my own hurdles). FYI: I do know that [[]] does not exist in C++. If you want to advocate your beautiful project, please provide step-in docs for what you can do with it (in particular: lists and data.frames need work). For us dummies. – Nick Sabbe May 13 '11 at 13:43
  • 5
    Well, find me (or Romain) funding equivalent of a full day-job and we can write more documentation. Someone needs to feed the cat and pay the rent. – Dirk Eddelbuettel May 13 '11 at 13:46
  • 7
    Or do what Christian does so well with Rcpp-quickref: Send us patches! If you have a strong view on where documentation is lacking, or would have been better placed: make your case with a patch! – Dirk Eddelbuettel May 13 '11 at 13:50
  • @DirkEddelbuettel: I have to agree with Nick Sabbe, I find it hard to use the Rcpp documentation. I read the introduction and the vignettes, which have nice examples. These tell me a bit how to use List, but I still can't find where List is documented more generally. It was quite by accident that I discovered List has a 'push_back' method. I can't even find the header file that defines List. I have to say that Rcpp is a great package, all things considered, but your answer here seems a bit off-the-mark. Where exactly are Nick's questions about the List interface officially answered? – Metamorphic Jun 07 '16 at 11:13