Hi Davor,<div><br></div><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>
<div><br></div><div>-Kevin<br><br><div class="gmail_quote">On Thu, Feb 7, 2013 at 10:05 AM, Davor Cubranic <span dir="ltr"><<a href="mailto:cubranic@stat.ubc.ca" target="_blank">cubranic@stat.ubc.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">I have a CharacterVector from which I try to extract an element and assign it to a std::string:<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div><br></div><div>CharacterVector xs;</div><div>...</div><div>std::string x = as<std::string>(xs(0));</div></blockquote><div><br></div><div>This throws exception: "expecting a string". Why? Looking with the debugger at "xs", this is what I see:</div>
<div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div>(gdb) print xs</div></div><div><div>$6 = (CharacterVector &) @0x7fff5fbfcca0: {</div></div><div><div>  <Rcpp::RObject> = {</div>
</div><div><div>    _vptr$RObject = 0x1061979d0, </div></div><div><div>    m_sexp = 0x10582b618</div></div><div><div>  }, </div></div><div><div>  <Rcpp::VectorBase<16,true,Rcpp::Vector<16> >> = {</div></div>
<div><div>    <Rcpp::traits::expands_to_logical__impl<16>> = {<No data fields>}, <No data fields>}, </div></div><div><div>  <Rcpp::internal::eval_methods<16>> = {<No data fields>}, </div>
</div><div><div>  members of Rcpp::Vector<16>: </div></div><div><div>  cache = {</div></div><div><div>    p = 0x7fff5fbfcca0</div></div><div><div>  }</div></div><div><div>}</div></div></blockquote><div><br></div><div>
I've no idea how to poke any deeper and see what the actual R object in the first element of the vector is. Can anyone help with this?</div><div><br></div><div>This is with R 2.15.2 and Rcpp 0.10.2 on OS X 10.7.5. The code in question worked fine with Rcpp 0.10.0.</div>
<span class="HOEnZb"><font color="#888888"><div><br></div><div>Davor</div></font></span></div><br>_______________________________________________<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>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br></blockquote></div><br></div>