<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I tracked this down to const-ness:<blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><br></div><div><div><div>bar <- cxxfunction(signature(xs_="character"), plugin='Rcpp', body='</div></div></div><div><div><div>const CharacterVector xs(xs_);</div></div></div><div><div><div>const std::string x(xs(0));</div></div></div><div><div><div>Rcout << x << std::endl;')</div></div></div></blockquote><div><div><br></div><div>fails with the compile error mentioned in my last message, while</div><div><br></div></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div>foo <- cxxfunction(signature(xs_="character"), plugin='Rcpp', body='</div></div><div><div>CharacterVector xs(xs_);</div></div><div><div>std::string x(xs(0));</div></div><div><div>Rcout << x << std::endl;')</div></div><div><div><br></div></div><div><div>foo(month.abb)</div></div></blockquote><div><div><br></div><div>works fine. I'll be happy to add a unit test to the package if the devs want it.</div><div><br></div><div>And to go back to my initial qustion: I'm still not sure why "as<std::string>" doesn't work:</div><div><br></div></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><div>baz <- cxxfunction(signature(xs_="character"), plugin='Rcpp', body='</div><div>CharacterVector xs(xs_);</div><div>std::string x = as<std::string>(xs(0));</div><div>Rcout << x << std::endl;')</div><div><br></div><div>baz(month.abb)</div></div></div></blockquote><div><div><br></div><div>will throw "expecting a string".</div><div><br></div><div>Davor</div><div><br></div><div><br></div></div><div><div><div>On 2013-02-07, at 10:27 AM, Davor Cubranic wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On 2013-02-07, at 10:15 AM, Kevin Ushey wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>One trick to get around this is to 'as' the entire CharacterVector into a std::vector< std::string >, and then index based off of that.</div><div><br></div><div>My guess is though, elements of CharacterVectors are 'const char*' s, so to convert them to strings you might want to just use std::string constructor, eg. std::string( xs(0) ).</div></blockquote><div><br></div>That used to work with 0.10.0, but when I upgraded this morning to 0.10.2, gives me the following compile error:</div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div>rcppdb.cpp:131: error: no matching function for call to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(SEXPREC* const&)'</div><div>/usr/include/c++/4.2.1/bits/basic_string.tcc:233: note: candidates are: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(typename _Alloc::rebind<_CharT>::other::size_type, _CharT, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]</div><div>/usr/include/c++/4.2.1/bits/basic_string.tcc:226: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]</div><div>/usr/include/c++/4.2.1/bits/basic_string.tcc:219: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, typename _Alloc::rebind<_CharT>::other::size_type, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]</div><div>/usr/include/c++/4.2.1/bits/basic_string.tcc:208: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::basic_string<_CharT, _Traits, _Alloc>&, typename _Alloc::rebind<_CharT>::other::size_type, typename _Alloc::rebind<_CharT>::other::size_type, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]</div><div>/usr/include/c++/4.2.1/bits/basic_string.tcc:197: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::basic_string<_CharT, _Traits, _Alloc>&, typename _Alloc::rebind<_CharT>::other::size_type, typename _Alloc::rebind<_CharT>::other::size_type) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]</div><div>/usr/include/c++/4.2.1/bits/basic_string.tcc:183: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]</div><div>/usr/include/c++/4.2.1/bits/basic_string.tcc:191: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]</div><div>/usr/include/c++/4.2.1/bits/basic_string.h:2065: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]</div><div>make: *** [rcppdb.o] Error 1</div></div><div><br></div></blockquote><div>Perhaps this is caused by the same bug, introduced somewhere post-0.10.0.</div><div><br></div>Davor</div>_______________________________________________<br>Rcpp-devel mailing list<br><a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</blockquote></div><br></div></body></html>