<html><head></head><body bgcolor="#FFFFFF"><div><br></div><div>Le 23 oct. 2011 à 05:52, Michael Hannon <<a href="mailto:jm_hannon@yahoo.com">jm_hannon@yahoo.com</a>> a écrit :<br><br></div><div></div><blockquote type="cite"><div><span>Greetings. I'm trying to pick off, in C++, one component, which is a matrix,</span><br><span>from an R list.</span><br><span></span><br><span>In the first appended example, starting with:</span><br><span></span><br><span> ** A list containing a matrix</span><br><span></span><br><span>I pass a list from R to C++ and pick it off with a simple assignment</span><br><span>statement:</span><br><span></span><br><span> ccode = '</span><br><span> Rcpp::List l(l_R);</span><br><span> Rcpp::IntegerMatrix m = l["m"];;</span><br><span> [...]</span><br><span></span><br><span>This seems to work just fine.</span><br><span></span><br><span>But in the second appended example, starting with:</span><br><span></span><br><span> ** Putting it into a class</span><br><span></span><br><span>the seemingly equivalent statement in the body of a class constructor fails</span><br><span>with a compilation error:</span><br><span></span><br><span> includes = '</span><br><span> class CCC{</span><br><span> public:</span><br><span> CCC(Rcpp::List l){</span><br><span> m = l["m"];</span><br><span> }</span><br><span> [...]</span><br><span> private:</span><br><span> Rcpp::IntegerMatrix m;</span><br><span> }</span><br><span> '</span><br></div></blockquote><div><br></div><div>Here you are trying to use the assignment operator, we could not manage to remove the ambiguity. </div><div><br></div><div>In the first example, you use the ctor, and in this case we managed the disambiguation. </div><div><br></div><div>i would advise using this as the ctor of CCC :</div><div><br></div><blockquote type="cite"><div><font class="Apple-style-span" color="#000000"> CCC(Rcpp::List l) : m( l["m"] ) {}<br></font></div></blockquote><div><br></div><div>Romain</div><br><blockquote type="cite"><div><span>Error in compileCode(f, code, language = language, verbose = verbose) : </span><br><span> Compilation ERROR, function(s)/method(s) not created! file33334060.cpp: In</span><br><span>constructor ‘CCC::CCC(Rcpp::List)’:</span><br><span>file33334060.cpp:23:16: error: ambiguous overload for ‘operator=’ in</span><br><span>‘((CCC*)this)->CCC::m = Rcpp::Vector<RTYPE>::operator[](const string&) [with</span><br><span>int RTYPE = 19, Rcpp::Vector<RTYPE>::NameProxy =</span><br><span>Rcpp::internal::generic_name_proxy<19>, std::string =</span><br><span>std::basic_string<char>]((* & std::basic_string<char>(((const char*)"m"),</span><br><span>(*(const std::allocator<char>*)(& std::allocator<char>())))))’</span><br><span>[...]</span><br><span></span><br><span></span><br><span>My sessionInfo() output is at the very bottom of this message.</span><br><span></span><br><span>Any idea what I'm doing wrong?</span><br><span></span><br><span>Thanks,</span><br><span></span><br><span>-- Mike</span><br><span></span><br><span></span><br><span>** A list containing a matrix</span><br><span>#+begin_src R</span><br><span> library(Rcpp)</span><br><span> library(inline)</span><br><span> </span><br><span> includes = '</span><br><span> '</span><br><span> ccode = '</span><br><span> Rcpp::List l(l_R);</span><br><span> Rcpp::IntegerMatrix m = l["m"];</span><br><span> return Rcpp::wrap(m(2,0));</span><br><span> '</span><br><span> fn = cxxfunction(</span><br><span> sig = signature(l_R = "list"),</span><br><span> body = ccode,</span><br><span> includes = includes,</span><br><span> plugin = "Rcpp")</span><br><span> </span><br><span> m <- matrix(1:6, ncol = 2)</span><br><span> l <- list(m = m, a = 14)</span><br><span> fn(l)</span><br><span> </span><br><span>#+end_src</span><br><span></span><br><span>#+results:</span><br><span>: 3</span><br><span></span><br><span>** Putting it into a class</span><br><span>#+begin_src R</span><br><span> library(Rcpp)</span><br><span> library(inline)</span><br><span> </span><br><span> includes = '</span><br><span> class CCC{</span><br><span> public:</span><br><span> CCC(Rcpp::List l){</span><br><span> m = l["m"];</span><br><span> }</span><br><span> Rcpp::IntegerMatrix mGet(){</span><br><span> return m;</span><br><span> }</span><br><span> private:</span><br><span> Rcpp::IntegerMatrix m;</span><br><span> }</span><br><span> '</span><br><span> ccode = '</span><br><span> Rcpp::List l(l_R);</span><br><span> CCC ccc(l_R);</span><br><span> return Rcpp::wrap(ccc.mGet());</span><br><span> '</span><br><span> fn = cxxfunction(</span><br><span> sig = signature(l_R = "list"),</span><br><span> body = ccode,</span><br><span> includes = includes,</span><br><span> plugin = "Rcpp")</span><br><span> </span><br><span> m <- matrix(1:6, ncol = 2)</span><br><span> l <- list(m = m, a = 14)</span><br><span> fn(l)</span><br><span> </span><br><span>#+end_src</span><br><span></span><br><span>#+results:</span><br><span></span><br><span></span><br><span></span><br><blockquote type="cite"><span>sessionInfo()</span><br></blockquote><span>R version 2.13.1 (2011-07-08)</span><br><span>Platform: x86_64-redhat-linux-gnu (64-bit)</span><br><span></span><br><span>locale:</span><br><span> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 </span><br><span> [4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=C</span><br><span>LC_MESSAGES=en_US.UTF-8 </span><br><span> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C </span><br><span>[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C </span><br><span></span><br><span>attached base packages:</span><br><span>[1] stats graphics grDevices datasets utils methods base </span><br><span></span><br><span>_______________________________________________</span><br><span>Rcpp-devel mailing list</span><br><span><a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a></span><br><span><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></span></div></blockquote></body></html>