<html><body><div style="color:#000; background-color:#fff; font-family:lucida console, sans-serif;font-size:12pt"><div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Greetings. I'm trying to bootstrap my way into Rcpp. I have the impression</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">that the "Sugar" extension to Rcpp allows one to use R syntax to run a</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">substantial subset of R<span class="Apple-tab-span" style="white-space:pre">        </span>commands within C++ (i.e., using native C++ code, not</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">calling back to R). If that's the case, I evidently have a gaping hole in my</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">understanding.</font></div><div><font class="Apple-style-span"
face="'lucida console', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">I tried to run the following R program, but I couldn't get the C++ part to</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">compile:</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> library(Rcpp)</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> library(inline)</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> xorig <- c(1, -2, 3, -4, 5, -6, 7)</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">
</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> code <- '</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> NumericVector x(xs);</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> return sapply( x, abs );</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> '</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> xabs <- cxxfunction(signature(xs="numeric"),</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> plugin="Rcpp",</font></div><div><font
class="Apple-style-span" face="'lucida console', sans-serif"> body=code)</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> xabs(xorig)</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">I've appended the output of one of my attempts. I'd appreciate it if somebody</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">could point me in the right direction here.</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">--
Mike</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">$ R --vanilla < mhSugar.R</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">R version 2.13.1 (2011-07-08)</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Copyright (C) 2011 The R Foundation for Statistical Computing</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">ISBN 3-900051-07-0</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Platform: x86_64-redhat-linux-gnu
(64-bit)</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">R is free software and comes with ABSOLUTELY NO WARRANTY.</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">You are welcome to redistribute it under certain conditions.</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Type 'license()' or 'licence()' for distribution details.</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> Natural language support but running in an English locale</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">R is a collaborative project
with many contributors.</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Type 'contributors()' for more information and</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">'citation()' on how to cite R or R packages in publications.</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Type 'demo()' for some demos, 'help()' for on-line help, or</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">'help.start()' for an HTML browser interface to help.</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Type 'q()' to quit R.</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">>
library(Rcpp)</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">> library(inline)</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">> </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">> xorig <- c(1, -2, 3, -4, 5, -6, 7)</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">> </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">> code <- '</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">+ NumericVector x(xs);</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">+ return sapply( x, abs );</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">+ '</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">>
</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">> xabs <- cxxfunction(signature(xs="numeric"),</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">+ plugin="Rcpp",</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">+ body=code)</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">file666a1f9c.cpp: In function ‘SEXPREC* file666a1f9c(SEXP)’:</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">file666a1f9c.cpp:32:27: error: no matching function for call to</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">‘sapply(Rcpp::NumericVector&, <unresolved overloaded function
type>)’</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">file666a1f9c.cpp:32:27: note: candidate is:</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">/usr/lib64/R/library/Rcpp/include/Rcpp/sugar/functions/sapply.h:103:1: note:</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">template<int RTYPE, bool NA, class T, class Function></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::sugar::Sapply<RTYPE, NA, T, Function, Rcpp::traits::same_type<typename</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::traits::result_of<Function>::type, typename</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::traits::storage_type<Rcpp::traits::r_sexptype_traits<typename</font></div><div><font class="Apple-style-span"
face="'lucida console', sans-serif">Rcpp::traits::result_of<Function>::type>::rtype>::type>::value></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::sapply(const Rcpp::VectorBase<RTYPE, LHS_NA, LHS_T>&, Function)</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">make: *** [file666a1f9c.o] Error 1</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">ERROR(s) during compilation: source code errors or compiler configuration</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">errors!</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Program source:</font></div><div><font
class="Apple-style-span" face="'lucida console', sans-serif"> 1: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 2: // includes from the plugin</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 3: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 4: #include <Rcpp.h></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 5: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 6: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 7: #ifndef BEGIN_RCPP</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 8: #define BEGIN_RCPP</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 9: #endif</font></div><div><font
class="Apple-style-span" face="'lucida console', sans-serif"> 10: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 11: #ifndef END_RCPP</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 12: #define END_RCPP</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 13: #endif</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 14: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 15: using namespace Rcpp;</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 16: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 17: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 18: // user includes</font></div><div><font
class="Apple-style-span" face="'lucida console', sans-serif"> 19: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 20: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 21: // declarations</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 22: extern "C" {</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 23: SEXP file666a1f9c( SEXP xs) ;</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 24: }</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 25: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 26: // definition</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 27: </font></div><div><font
class="Apple-style-span" face="'lucida console', sans-serif"> 28: SEXP file666a1f9c( SEXP xs ){</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 29: BEGIN_RCPP</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 30: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 31: NumericVector x(xs);</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 32: return sapply( x, abs );</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 33: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 34: END_RCPP</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 35: }</font></div><div><font class="Apple-style-span" face="'lucida console',
sans-serif"> 36: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 37: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Error in compileCode(f, code, language = language, verbose = verbose) : </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> Compilation ERROR, function(s)/method(s) not created! file666a1f9c.cpp: In</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">function ‘SEXPREC* file666a1f9c(SEXP)’:</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">file666a1f9c.cpp:32:27: error: no matching function for call to</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">‘sapply(Rcpp::NumericVector&, <unresolved overloaded function type>)’</font></div><div><font class="Apple-style-span" face="'lucida
console', sans-serif">file666a1f9c.cpp:32:27: note: candidate is:</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">/usr/lib64/R/library/Rcpp/include/Rcpp/sugar/functions/sapply.h:103:1: note:</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">template<int RTYPE, bool NA, class T, class Function></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::sugar::Sapply<RTYPE, NA, T, Function, Rcpp::traits::same_type<typename</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::traits::result_of<Function>::type, typename</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::traits::storage_type<Rcpp::traits::r_sexptype_traits<typename</font></div><div><font class="Apple-style-span" face="'lucida console',
sans-serif">Rcpp::traits::result_of<Function>::type>::rtype>::type>::value></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::sapply(const Rcpp::VectorBase<RTYPE, LHS_NA, LHS_T>&, Function)</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">make: *** [file666a1f9c.o] Error 1</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Calls: cxxfunction -> compileCode</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">In addition: Warning message:</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">running command '/usr/lib64/R/bin/R CMD SHLIB file666a1f9c.cpp 2></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">file666a1f9c.cpp.err.txt' had status 1 </font></div><div><font class="Apple-style-span" face="'lucida console',
sans-serif">Execution halted</font></div><div style="font-family: 'lucida console', sans-serif; font-size: 12pt; "><br></div></div></div></body></html>