<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 need to return a list of initially-indeterminate length from</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">C++. I found the following note from Romain:</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"> http://article.gmane.org/gmane.comp.lang.r.rcpp/69/match=push%5fback+list</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">that seemed to solve the problem.</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 made what I thought were some minor tweaks to the example (using cxxfunction</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">instead of cfunction, for instance) and tried to run it on my system.</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">The example works fine if I leave out the push of the character string:</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"> myList.push_back(Rcpp::Named ("foo", "bar"));</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">but fails with an obscure (to me) compilation error when I include it.</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've appended first the R code and after that the log of an R session in which</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">I tried to run the code.</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 might add that I've tried some variations of the problematic line but have</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">always gotten compile errors. Here are a couple of examples:</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"> myList.push_back(Named ("foo", "bar"));</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> myList.push_back(Rcpp::Named ("foo", 10));</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">Thanks for any help you can provide.</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">########## R code</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"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">includes <- '</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"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">ccode <- '</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> Rcpp::List myList(rList);</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> myList.push_back(10);</font></div><div><font class="Apple-style-span" face="'lucida console',
sans-serif"> myList.push_back(Rcpp::Named ("foo", "bar"));</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> return myList;</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"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">lfun <- cxxfunction(signature(rList = "list"),</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> includes = includes,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> body = ccode,</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"><br></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">rL <- list(x=1:4, y=letters[1:4])</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">lfun(rL)</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">########## Log of an R session that exhibits the compilation problem</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 < pushback.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">> includes <- '</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">> ccode <- '</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">+ Rcpp::List myList(rList);</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">+ myList.push_back(10);</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">+ myList.push_back(Rcpp::Named ("foo", "bar"));</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">+ return myList;</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">> lfun <- cxxfunction(signature(rList = "list"),</font></div><div><font class="Apple-style-span"
face="'lucida console', sans-serif">+ includes = includes,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">+ body = ccode,</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">In file included from /usr/lib64/R/library/Rcpp/include/RcppCommon.h:313:0,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> from /usr/lib64/R/library/Rcpp/include/Rcpp.h:27,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">
from file35af62e2.cpp:4:</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h: In function ‘SEXPREC*</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::internal::wrap_dispatch_unknown_iterable(const T&,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::traits::false_type) [with T = Rcpp::traits::named_object<char [4]>, SEXP</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">= SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant<bool,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">false>]’:</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h:638:98:
instantiated</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">from ‘SEXPREC* Rcpp::internal::wrap_dispatch_unknown(const T&,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::traits::false_type) [with T = Rcpp::traits::named_object<char [4]>, SEXP</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">= SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant<bool,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">false>]’</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h:654:96: instantiated</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">from ‘SEXPREC* Rcpp::internal::wrap_dispatch_eigen(const T&,</font></div><div><font class="Apple-style-span"
face="'lucida console', sans-serif">Rcpp::traits::false_type) [with T = Rcpp::traits::named_object<char [4]>, SEXP</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">= SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant<bool,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">false>]’</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h:669:80: instantiated</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">from ‘SEXPREC* Rcpp::internal::wrap_dispatch_unknown_importable(const T&,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::traits::false_type) [with T = Rcpp::traits::named_object<char [4]>, SEXP</font></div><div><font class="Apple-style-span" face="'lucida console',
sans-serif">= SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant<bool,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">false>]’</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h:687:99: instantiated</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">from ‘SEXPREC* Rcpp::internal::wrap_dispatch(const T&,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::traits::wrap_type_unknown_tag) [with T = Rcpp::traits::named_object<char</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">[4]>, SEXP = SEXPREC*]’</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h:791:104:
instantiated</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">from ‘SEXPREC* Rcpp::wrap(const T&) [with T = Rcpp::traits::named_object<char</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">[4]>, SEXP = SEXPREC*]’</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">/usr/lib64/R/library/Rcpp/include/Rcpp/vector/converter.h:68:31:</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">instantiated from ‘static SEXPREC*</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::internal::generic_element_converter<RTYPE>::get(const T&) [with T =</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::traits::named_object<char [4]>, int RTYPE = 19, SEXP = SEXPREC*]’</font></div><div><font class="Apple-style-span" face="'lucida
console', sans-serif">/usr/lib64/R/library/Rcpp/include/Rcpp/vector/Vector.h:440:9: instantiated</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">from ‘void Rcpp::Vector<RTYPE>::push_back(const T&) [with T =</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::traits::named_object<char [4]>, int RTYPE = 19]’</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">file35af62e2.cpp:34:48: instantiated from here</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h:433:11: error: cannot</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">convert ‘const Rcpp::traits::named_object<char [4]>’ to ‘SEXP’ in</font></div><div><font class="Apple-style-span" face="'lucida console',
sans-serif">initialization</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">make: *** [file35af62e2.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: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 22: // declarations</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 23: extern "C" {</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 24: SEXP file35af62e2( SEXP rList) ;</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: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 27: // definition</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 28: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 29: SEXP file35af62e2( SEXP rList ){</font></div><div><font class="Apple-style-span" face="'lucida
console', sans-serif"> 30: BEGIN_RCPP</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 31: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 32: Rcpp::List myList(rList);</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 33: myList.push_back(10);</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 34: myList.push_back(Rcpp::Named ("foo", "bar"));</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 35: return myList;</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: END_RCPP</font></div><div><font class="Apple-style-span" face="'lucida console',
sans-serif"> 38: }</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 39: </font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> 40: </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! In file included from</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">/usr/lib64/R/library/Rcpp/include/RcppCommon.h:313:0,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif"> from /usr/lib64/R/library/Rcpp/include/Rcpp.h:27,</font></div><div><font class="Apple-style-span" face="'lucida console',
sans-serif"> from file35af62e2.cpp:4:</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h: In function ‘SEXPREC*</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::internal::wrap_dispatch_unknown_iterable(const T&,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::traits::false_type) [with T = Rcpp::traits::named_object<char [4]>, SEXP</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">= SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant<bool,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">false>]’:</font></div><div><font class="Apple-style-span" face="'lucida console',
sans-serif">/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h:638:98: instantiated</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">from ‘SEXPREC* Rcpp::internal::wrap_dispatch_unknown(const T&,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">Rcpp::traits::false_type) [with T = Rcpp::traits::named_object<char [4]>, SEXP</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">= SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant<bool,</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">false>]’</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h:654:96: instantiated</font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">from ‘SEXPREC*
Rcpp::internal::wrap_dispatch_eigen(const</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 file35af62e2.cpp 2></font></div><div><font class="Apple-style-span" face="'lucida console', sans-serif">file35af62e2.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>