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

2013-02-07 Thread Romain Francois
Thanks. I will fix it. Romain Le 8 févr. 2013 à 05:28, Davor Cubranic a écrit : > On 13-02-07 07:24 PM, Davor Cubranic wrote: >> The version assigning an element of a const CharacterVector to a const >> std::string (named "bar" below) compiles and works fine in Rcpp 0.9.14, >> so the problem w

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

2013-02-07 Thread Davor Cubranic
On 13-02-07 07:24 PM, Davor Cubranic wrote: The version assigning an element of a const CharacterVector to a const std::string (named "bar" below) compiles and works fine in Rcpp 0.9.14, so the problem was introduced after that. To be more precise, it was introduced after 0.10.0 and before 0.10

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

2013-02-07 Thread Davor Cubranic
The version assigning an element of a const CharacterVector to a const std::string (named "bar" below) compiles and works fine in Rcpp 0.9.14, so the problem was introduced after that. On the other hand, "as" (function "baz") fails as in 0.10.2, probably for the same reason Kevin identified in

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

2013-02-07 Thread Kevin Ushey
Perhaps this will narrow down the 'why as seems to fail'. I'm looking at the Rcpp 0.10.2 source. (hopefully I've got this right): Rcpp's 'as' uses ::Rf_isString to check whether the item passed is a string; or more specifically, a STRSXP. However, elements within a CharacterVector seem to be of 't

Re: [Rcpp-devel] Performance question about DataFrame

2013-02-07 Thread Davor Cubranic
I come late to this discussion, but it should be pointed out that using "sprintf" without ensuring that your buffer is long enough is not a "subtlety" but a bug. A more "C++ way" to do it, and most importantly safer, would be to use std::ostringstream: for (int i = 0; i < nrows; i++) { std::

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

2013-02-07 Thread Davor Cubranic
I tracked this down to const-ness: bar <- cxxfunction(signature(xs_="character"), plugin='Rcpp', body=' const CharacterVector xs(xs_); const std::string x(xs(0)); Rcout << x << std::endl;') fails with the compile error mentioned in my last message, while foo <- cxxfunction(signature(xs_="charact

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

2013-02-07 Thread Dirk Eddelbuettel
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", "

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

2013-02-07 Thread Davor Cubranic
On 2013-02-07, at 10:15 AM, Kevin Ushey wrote: > 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 yo

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

2013-02-07 Thread Kevin Ushey
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,

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

2013-02-07 Thread Davor Cubranic
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(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 &) @0

Re: [Rcpp-devel] Rstudio package build and Rcpp::compileAttributes()

2013-02-07 Thread Smith, Dale
Thanks, I'll try this out when I get a chance. Dale Smith, Ph.D. Senior Financial Quantitative Analyst Risk & Compliance Fiserv Office: 678-375-5315 www.fiserv.com -Original Message- From: JJ Allaire [mailto:jj.alla...@gmail.com] Sent: Thursday, February 07, 2013 11:49 AM To: Smith, Dale

Re: [Rcpp-devel] Rstudio package build and Rcpp::compileAttributes()

2013-02-07 Thread JJ Allaire
Hi Dale, In order to ensure that the RcppExports.cpp file is correct it needs to be deterministically generated, so in all cases we need write access to it. One possible workaround is this: - Use a custom SOURCES variable in Makevars to explicitly list the source files to compile as part of the p

[Rcpp-devel] Rstudio package build and Rcpp::compileAttributes()

2013-02-07 Thread Smith, Dale
Hello all, I'm using Rstudio 0.97.306, R 2.15-2, and Rcpp 0.10.2 with Windows 7 Professional x64. I recently switched to using the build tool in Rstudio, however, my generated file RcppExports.cpp and RcppExports.R are checked into version control, so they are read-only. The build fails with