<div dir="ltr">Great. Thanks for the quick response and all the work you and Romain put into Rcpp!<div><br></div><div style>-Kevin</div><div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 29, 2013 at 9:35 AM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
On 29 March 2013 at 08:48, Kevin Ushey wrote:<br>
| Thanks for the quick responses.<br>
<br>
</div>Thanks for the reproducible bug report.<br>
<br>
In (some version of) Rcpp 0.10.3.1 [1] you can now use your function again:<br>
<br>
R> sourceCpp("/tmp/kevin.cpp")<br>
R> set.seed(42)<br>
R> x <- sample(1:10, 20, replace=TRUE)<br>
R> table(x)<br>
x<br>
2 3 5 6 7 8 9 10<br>
2 2 3 2 2 3 1 5<br>
R> counts(x)<br>
2 3 5 6 7 8 9 10<br>
2 2 3 2 2 3 1 5<br>
R><br>
<div class="im"><br>
<br>
| It seems counter-productive for R Core to be<br>
| removing API entry points, at least doing so without informing package<br>
<br>
</div>Not quite as we were using a non-exported function. The counter-productive<br>
nature of this is solely on "their" decision of what is, and what is not,<br>
part of the API. If we use something we are not supposed to use, we get to<br>
pay the price of it being pulled.<br>
<br>
"They" are pretty good about maintaining what is the declared API.<br>
<div class="im"><br>
| maintainers of newly implemented and tested alternatives. I wonder if it's due<br>
| to the introduction of 'long' vectors, and the team decided it would be easier<br>
| to just remove the API entry points, rather than adapting them? Just<br>
| conjecture, though.<br>
<br>
</div>No relationship.<br>
<br>
Dirk<br>
<br>
[1] In attempting to address the long-standding (and very annoying) but with<br>
Date.Frame, Romain inadvertently broke SVN trunk. And I am not managing to<br>
get it back right now. But if you apply my revision 4297 to, say, the 0.10.3<br>
release (and hence ignore the Data.Frame change) then the resulting 0.10.3.1<br>
build, tests, and gets your counts() function back.<br>
<div class="HOEnZb"><div class="h5"><br>
|<br>
| Thanks for the help.<br>
| -Kevin<br>
|<br>
| On Fri, Mar 29, 2013 at 8:20 AM, <<a href="mailto:romain@r-enthusiasts.com">romain@r-enthusiasts.com</a>> wrote:<br>
|<br>
| Cool. I'll have a look when I'm back from easter weekend.<br>
|<br>
| Romain<br>
|<br>
| Le 2013-03-29 16:00, Dirk Eddelbuettel a écrit :<br>
|<br>
|<br>
| On 29 March 2013 at 09:40, Dirk Eddelbuettel wrote:<br>
| |<br>
| | On 29 March 2013 at 15:24, <a href="mailto:romain@r-enthusiasts.com">romain@r-enthusiasts.com</a> wrote:<br>
| | | Le 2013-03-29 14:31, Dirk Eddelbuettel a écrit :<br>
| | | > On 29 March 2013 at 09:11, <a href="mailto:romain@r-enthusiasts.com">romain@r-enthusiasts.com</a> wrote:<br>
| | | > |<br>
| | | > | Hello,<br>
| | | > |<br>
| | | > | This is related to this change:<br>
| | | > |<br>
| | | > | 2013-01-15 Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</a>><br>
| | | > |<br>
| | | > | * src/api.cpp (Rcpp): Commented-out<br>
| coerce_to_string() for real<br>
| | | > and<br>
| | | > | complex arguments as R-devel (as of today) dislikes<br>
| use of non-API<br>
| | | > | functions Rf_EncodeComplex’, ‘Rf_EncodeReal’,<br>
| ‘Rf_formatComplex’<br>
| | | > |<br>
| | | > | So maybe Dirk has a plan to fix it.<br>
| | | ><br>
| | | > I do not.<br>
| | |<br>
| | | Fine. So I'll fix it.<br>
| |<br>
| | Hold on.<br>
| |<br>
| | I am in the middle of it. I do have a poor replacementment for<br>
| EncodeReal,<br>
| | and am about to test one for complex. Will post soon.<br>
| |<br>
| | Am not covering scientific notation at this point.<br>
|<br>
| Ok, here replacement candidates. Kudos to Kevin for sending something<br>
| reproducible that triggered this. This snipped below grew from his<br>
| code and<br>
| provids replacement candidates for coerce_to_string() for the real and<br>
| complex cases, not using the internal R functions (which I also did not<br>
| look<br>
| at). Obviously the function headers need to change from the sample to<br>
| what<br>
| api.cpp uses.<br>
|<br>
| What we get is simple snprintf() calls which almost surely is less<br>
| featureful<br>
| than what R has, but please complaon to R Core about the sillyness of<br>
| us not<br>
| being able to use _existing and tested functions_. It's painful.<br>
|<br>
|<br>
| Dirk<br>
|<br>
| #include <Rcpp.h><br>
|<br>
| static const char* dropTrailing0(char *s, char cdec) {<br>
| /* Note that 's' is modified */<br>
| char *p = s;<br>
| for (p = s; *p; p++) {<br>
| if(*p == cdec) {<br>
| char *replace = p++;<br>
| while ('0' <= *p && *p <= '9')<br>
| if(*(p++) != '0')<br>
| replace = p;<br>
| if(replace != p)<br>
| while((*(replace++) = *(p++)))<br>
| ;<br>
| break;<br>
| }<br>
| }<br>
| return s;<br>
| }<br>
|<br>
| //template <><br>
| // const char* coerce_to_string/*<REALSXP>*/(double x){<br>
| // [[Rcpp::export]]<br>
| const char* coerce_to_stringRE(double x){<br>
| int w,d,e ;<br>
| // cf src/main/format.c in R's sources:<br>
| // The return values are<br>
| // w : the required field width<br>
| // d : use %w.df in fixed format, %#<a href="http://w.de" target="_blank">w.de</a> in scientific<br>
| format<br>
| // e : use scientific format if != 0, value is number of<br>
| exp<br>
| digits - 1<br>
| //<br>
| // nsmall specifies the minimum number of decimal digits in<br>
| fixed format:<br>
| // it is 0 except when called from do_format.<br>
| Rf_formatReal( &x, 1, &w, &d, &e, 0 ) ;<br>
| // we are no longer allowed to use this:<br>
| // char* tmp = const_cast<char*>( Rf_EncodeReal(x, w, d, e,<br>
| '.') );<br>
| // so approximate it poorly as<br>
| char tmp[128];<br>
| snprintf(tmp, 127, "%*.*f", w, d, x);<br>
| //Rcpp::Rcout << "Vec is " << vec << std::endl;<br>
| return dropTrailing0(tmp, '.');<br>
|<br>
| }<br>
|<br>
| //template <><br>
| //const char* coerce_to_string/*<CPLXSXP>*/(Rcomplex x){<br>
| // [[Rcpp::export]]<br>
| std::string coerce_to_stringCP(Rcomplex x){<br>
| int wr, dr, er, wi, di, ei;<br>
| // cf src/main/format.c in R's sources:<br>
| Rf_formatComplex(&x, 1, &wr, &dr, &er, &wi, &di, &ei, 0);<br>
| //return Rf_EncodeComplex(x, wr, dr, er, wi, di, ei, '.' );<br>
|<br>
| // we are no longer allowed to use this:<br>
| // Rf_EncodeComplex(x, wr, dr, er, wi, di, ei, '.' );<br>
| // so approximate it poorly as<br>
| char tmp[128];<br>
| snprintf(tmp, 127, "%*.*f+%*.*fi", wr, dr, x.r, wi, di, x.i);<br>
| return std::string(tmp); // force a copy<br>
| }<br>
|<br>
| using namespace Rcpp;<br>
|<br>
| // // [[Rcpp::export]]<br>
| // IntegerVector counts(NumericVector x) {<br>
| // return table(x);<br>
| // }<br>
|<br>
|<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>
|<br>
|<br>
<br>
</div></div><div class="HOEnZb"><div class="h5">--<br>
Dirk Eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>
</div></div></blockquote></div><br></div></div></div>