[Rcpp-devel] Misunderstanding about sugar

Michael Hannon jm_hannon at yahoo.com
Fri Oct 21 04:58:34 CEST 2011


Greetings.  I'm trying to bootstrap my way into Rcpp.  I have the impression
that the "Sugar" extension to Rcpp allows one to use R syntax to run a
substantial subset of Rcommands within C++ (i.e., using native C++ code, not
calling back to R).  If that's the case, I evidently have a gaping hole in my
understanding.

I tried to run the following R program, but I couldn't get the C++ part to
compile:

    library(Rcpp)
    library(inline)
    
    xorig <- c(1, -2, 3, -4, 5, -6, 7)
      
    code <- '
        NumericVector x(xs);
        return sapply( x, abs );
    '
      
    xabs <- cxxfunction(signature(xs="numeric"),
                        plugin="Rcpp",
                        body=code)
      
    xabs(xorig)
  
I've appended the output of one of my attempts.  I'd appreciate it if somebody
could point me in the right direction here.

-- Mike



$ R --vanilla < mhSugar.R

R version 2.13.1 (2011-07-08)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-redhat-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(Rcpp)
> library(inline)
> 
> xorig <- c(1, -2, 3, -4, 5, -6, 7)
>   
> code <- '
+     NumericVector x(xs);
+     return sapply( x, abs );
+ '
>   
> xabs <- cxxfunction(signature(xs="numeric"),
+                     plugin="Rcpp",
+                     body=code)
file666a1f9c.cpp: In function ‘SEXPREC* file666a1f9c(SEXP)’:
file666a1f9c.cpp:32:27: error: no matching function for call to
‘sapply(Rcpp::NumericVector&, <unresolved overloaded function type>)’
file666a1f9c.cpp:32:27: note: candidate is:
/usr/lib64/R/library/Rcpp/include/Rcpp/sugar/functions/sapply.h:103:1: note:
template<int RTYPE, bool NA, class T, class Function>
Rcpp::sugar::Sapply<RTYPE, NA, T, Function, Rcpp::traits::same_type<typename
Rcpp::traits::result_of<Function>::type, typename
Rcpp::traits::storage_type<Rcpp::traits::r_sexptype_traits<typename
Rcpp::traits::result_of<Function>::type>::rtype>::type>::value>
Rcpp::sapply(const Rcpp::VectorBase<RTYPE, LHS_NA, LHS_T>&, Function)
make: *** [file666a1f9c.o] Error 1

ERROR(s) during compilation: source code errors or compiler configuration
errors!

Program source:
  1: 
  2: // includes from the plugin
  3: 
  4: #include <Rcpp.h>
  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 file666a1f9c( SEXP xs) ;
 24: }
 25: 
 26: // definition
 27: 
 28: SEXP file666a1f9c( SEXP xs ){
 29: BEGIN_RCPP
 30: 
 31:     NumericVector x(xs);
 32:     return sapply( x, abs );
 33: 
 34: END_RCPP
 35: }
 36: 
 37: 
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! file666a1f9c.cpp: In
function ‘SEXPREC* file666a1f9c(SEXP)’:
file666a1f9c.cpp:32:27: error: no matching function for call to
‘sapply(Rcpp::NumericVector&, <unresolved overloaded function type>)’
file666a1f9c.cpp:32:27: note: candidate is:
/usr/lib64/R/library/Rcpp/include/Rcpp/sugar/functions/sapply.h:103:1: note:
template<int RTYPE, bool NA, class T, class Function>
Rcpp::sugar::Sapply<RTYPE, NA, T, Function, Rcpp::traits::same_type<typename
Rcpp::traits::result_of<Function>::type, typename
Rcpp::traits::storage_type<Rcpp::traits::r_sexptype_traits<typename
Rcpp::traits::result_of<Function>::type>::rtype>::type>::value>
Rcpp::sapply(const Rcpp::VectorBase<RTYPE, LHS_NA, LHS_T>&, Function)
make: *** [file666a1f9c.o] Error 1
Calls: cxxfunction -> compileCode
In addition: Warning message:
running command '/usr/lib64/R/bin/R CMD SHLIB file666a1f9c.cpp 2>
file666a1f9c.cpp.err.txt' had status 1 
Execution halted
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20111020/79a6ffbd/attachment-0001.htm>


More information about the Rcpp-devel mailing list