[Rcpp-devel] Is it C++ or Rcpp problem?

Darren Cook darren at dcook.org
Fri Sep 23 02:09:45 CEST 2011


In another thread Noah wrote "I wasn't asking a C++ question...I thought
there might have been a problem with Rcpp". No intention to pick on Noah
here, but I thought it was a good chance to suggest a simple
troubleshooting technique.

The technique is simple, but not so simple that it cannot have its own
name: Build It As A C++ Program.

You don't need a makefile for the kind of minimal example you'll post to
a mailing list, so:
  1. Slap your code in a file called tmp.cpp.
    (Don't forget header includes.)

  2. Whiz to a shell, in that directory.

  3. Dramatically type:
    g++ tmp.cpp

  4. If it compiles, rush to run it with:
    ./a.out

If it compiles and the Rcpp version does not, include both versions in
your mailing list post. The same if it runs but gives different output
to the Rcpp version.

Obviously if it does not compile standalone (*with the same error
message*) then you have a C++ question.

More information #1: if you get a *different* error message from
compiling in Rcpp, are you including some headers from outside the
standard library? First, see if they can be removed to make the example
smaller and clearer. If not, and you know where they are located,
specify with the -I flag:
  g++ -I/path/to/library/headers tmp.cpp

More information #2: Similarly if you are getting a linker error,
specify where to find a library with the -L flag, and the -l flag names
the library. E.g.
  g++ -L/usr/local/lib/R/site-library/RInside/lib -lRInside tmp.cpp

More information #3: Obviously at some point this becomes too complex an
exercise. But there is still one thing left to do, which is (in your R
script) pass the verbose=TRUE argument to cxxfunction().
This shows you the constructed source code and the compiler commandline
being used. A study of how it is different from your source code and
commandline, and why, can be enlightening sometimes.


Why bother? A few years back it was pointed out to me that whenever you
post to a mailing list it is being read by hundreds or thousands of
people. For instance if 350 people and each spends just 30 seconds
reading it... that works out at about 3 man-hours. When you look at it
like that, it is worth an extra 10 minutes of effort before sending
anything.

Since realizing this, about half my mailing list posts never get sent. I
discover the solution while adding little footnotes of additional
information :-)

Darren


-- 
Darren Cook, Software Researcher/Developer

http://dcook.org/work/ (About me and my work)
http://dcook.org/blogs.html (My blogs and articles)


More information about the Rcpp-devel mailing list