[Rcpp-devel] "expecting a string" and not finding it in a CharacterVector

Dirk Eddelbuettel edd at debian.org
Thu Feb 7 19:43:00 CET 2013


Davor, Kevin,

Allow to get into this intra-Vancouver exchange as I too dislike the sound of
"but this used to work"....  

A simple modifcation (see below) seems to do the trick:

R> sourceCpp("/tmp/davor.cpp")
R> getString(c("The", "quick", "brown", "fox"), 2)
[1] "brown"
R> getString(c("The", "quick", "brown", "fox"), 0)
[1] "The"
R> 

Here I do in fact go via char*. I too have the feeling that that didn't use
to be necessary --- but then "fear not" as we are currently getting better
string classes in Rcpp thanks to Romain (and to Hadley for funding).  So I
would just sit tight and wait things.  And maybe send us a new unit test for
two as the dozen or so we have for CharacterVector didn't catch this.

Dirk (hoping he understands what Davor was after in the first place...)


#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp::export]]
std::string getString(CharacterVector cv, int pos) {
  char *c = cv[pos];
  std::string s(c);
  return s;
}


-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


More information about the Rcpp-devel mailing list