<div dir="ltr">Thanks for the quick responses. It seems counter-productive for R Core to be removing API entry points, at least doing so without informing package maintainers of newly implemented and tested alternatives. I wonder if it's due to the introduction of 'long' vectors, and the team decided it would be easier to just remove the API entry points, rather than adapting them? Just conjecture, though.<div>


</div><div class="gmail_extra"><br></div><div class="gmail_extra">Thanks for the help.</div><div class="gmail_extra">-Kevin<br><br><div class="gmail_quote">On Fri, Mar 29, 2013 at 8:20 AM,  <span dir="ltr"><<a href="mailto:romain@r-enthusiasts.com" target="_blank">romain@r-enthusiasts.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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 :<div><div><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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" target="_blank">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" target="_blank">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" target="_blank">edd@debian.org</a>><br>
| | > |<br>
| | > |         * src/api.cpp (Rcpp): Commented-out coerce_to_string() for real<br>
| | > and<br>
| | > |         complex arguments as R-devel (as of today) dislikes use of non-API<br>
| | > |         functions Rf_EncodeComplex’, ‘Rf_EncodeReal’, ‘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 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 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 look<br>
at).  Obviously the function headers need to change from the sample to what<br>
api.cpp uses.<br>
<br>
What we get is simple snprintf() calls which almost surely is less featureful<br>
than what R has, but please complaon to R Core about the sillyness of 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>*/(<u></u>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 format<br>
    //     e : use scientific format if != 0, value is number of 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>
    // 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>*/(<u></u>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>
</blockquote>
<br></div></div><div><div>
______________________________<u></u>_________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-<u></u>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-<u></u>project.org/cgi-bin/mailman/<u></u>listinfo/rcpp-devel</a></div></div></blockquote></div><br>


</div></div>