[Rcpp-devel] "expecting a string" and not finding it in a CharacterVector
Kevin Ushey
kevinushey at gmail.com
Thu Feb 7 19:15:49 CET 2013
Hi Davor,
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.
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) ).
-Kevin
On Thu, Feb 7, 2013 at 10:05 AM, Davor Cubranic <cubranic at stat.ubc.ca>wrote:
> I have a CharacterVector from which I try to extract an element and assign
> it to a std::string:
>
>
> CharacterVector xs;
> ...
> std::string x = as<std::string>(xs(0));
>
>
> This throws exception: "expecting a string". Why? Looking with the
> debugger at "xs", this is what I see:
>
> (gdb) print xs
> $6 = (CharacterVector &) @0x7fff5fbfcca0: {
> <Rcpp::RObject> = {
> _vptr$RObject = 0x1061979d0,
> m_sexp = 0x10582b618
> },
> <Rcpp::VectorBase<16,true,Rcpp::Vector<16> >> = {
> <Rcpp::traits::expands_to_logical__impl<16>> = {<No data fields>}, <No
> data fields>},
> <Rcpp::internal::eval_methods<16>> = {<No data fields>},
> members of Rcpp::Vector<16>:
> cache = {
> p = 0x7fff5fbfcca0
> }
> }
>
>
> 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?
>
> 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.
>
> Davor
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130207/94bc16da/attachment-0001.html>
More information about the Rcpp-devel
mailing list