Installing R and Rcpp

Almost exactly a year ago, I wrote about my frustration calling C++ from R. Maybe this will become an annual event because I’m back at it.

This time my experience was more pleasant. I was able to install Rcpp on an Ubuntu virtual machine and run example 2.2 from the Rcpp FAQ once I upgraded R to the latest version. I wrote up some notes on the process of installing the latest version of R and Rcpp on Ubuntu.

I have not yet been able to run Rcpp on Windows.

Update: Thanks to Dirk Eddelbuettel for pointing out in the comments that you can install Rcpp from the shell rather than from inside R by running sudo apt-get install r-cran-rcpp. With this approach, I was able to install Rcpp without having to upgrade R first.

8 thoughts on “Installing R and Rcpp

  1. Also, I really agree with the ‘no to personal library’ as Unix/Linux are multi-user. The directory /usr/local/lib/R/site-library is of group staff — if you add yourself to that group you don’t need the sudo.

  2. Lastly, Rcpp on Windows works just fine too. It helps to have R and its libraries in a path without spaces, which is recommended but for some obscure reason never suggested/enforced by the R installer on Windows.

  3. Dirk: I’ve updated my blog post and the PDF notes to include installing Rcpp via apt-get.

    On Windows, I always install Unix-like software under C:bin to avoid problems with software that has trouble with spaces in paths.

    I was able to install Rcpp on Windows, but not able to get the example code to run. I ran the code from the same source file successfully on Linux, so I don’t believe there is an error in the code itself. R tells me

    ERROR(s) during compilation: source code errors or compiler configuration errors!
    
    Program source:
      1:
      2: // includes from the plugin
      3:
      4: #include 
      5:
      6:
      7: #ifndef BEGIN_RCPP
      8: #define BEGIN_RCPP
      9: #endif
     10:
     11: #ifndef END_RCPP
     12: #define END_RCPP
     13: #endif
     14:
     15: using namespace Rcpp;
     16:
     17:
     18: // user includes
     19:
     20:
     21: // declarations
     22: extern "C" {
     23: SEXP fileda0e163d0( SEXP x) ;
     24: }
     25:
     26: // definition
     27:
     28: SEXP fileda0e163d0( SEXP x ){
     29: BEGIN_RCPP
     30: NumericVector xx(x); return wrap( std::accumulate( xx.begin(), xx.end(), 0.0));
     31: END_RCPP
     32: }
     33:
     34:
    
    Error in compileCode(f, code, language = language, verbose = verbose) :
      Compilation ERROR, function(s)/method(s) not created!
    In addition: Warning message:
    running command 'C:/bin/R/R-2.15.1/bin/i386/R CMD SHLIB fileda0e163d0.cpp 2> fileda0e163d0.cpp.err.txt' had status 1 
  4. I think P.J. Brown categorized that sort of error message as one of his “deadly sins” in his compiler book.

    That was in the 1970′s, I suppose we’ll still be seeing the same type of thing thirty years from now.

  5. Hello John, just to add some info in case you are willing to come back to Windows the next year :-)

    In Windows, I had an error message similar to the one you show in comment #6, and, yes, I did install R in a folder with a name without spaces.

    I see in your message that the standard error is redirected to the file fileda0e163d0.cpp.err.txt, I had an error message referencing a file with a similar name but I did not find the file on my disk.

Comments are closed.