<div dir="ltr">Hi guys,<div><br></div><div>Sorry to be bringing this up so close after the CRAN release, but I just stumbled upon them today.</div><div><br></div><div>-----</div><div><br></div><div style>1) The table function occasionally produces names as '-0', rather than '0', for numeric vectors (haven't tested in other situations yet):</div>
<div style><br></div><div style><div>#include <Rcpp.h></div><div>using namespace Rcpp;</div><div><br></div><div>// [[Rcpp::export]]</div><div>IntegerVector counts(NumericVector x) {</div><div>  return table(x);</div>
<div>}</div><div><br></div><div>/*** R</div><div>set.seed(123)</div><div>x <- round( rnorm(100), 0 )</div><div>counts(x) ## names: -2, -1, -0, 1, 2</div><div><br></div><div style>y <- round( rnorm(1000), 0 )</div><div style>
counts(y) ## names: -3, -2, -1, 0, 1, 2, 3, as expected</div><div>*/</div><div><br></div><div>-----</div><div><br></div><div style>2) The table function doesn't return the correct names for factors:</div><div style><br>
</div><div style><div>#include <Rcpp.h></div><div>using namespace Rcpp;</div><div><br></div><div>// [[Rcpp::export]]</div><div>IntegerVector counts(IntegerVector x) {</div><div>  return table(x);</div><div>}</div><div>
<br></div><div>/*** R</div><div>set.seed(123)</div><div>x <- factor( round( rnorm(100), 0 ) )</div><div>counts(x) ## names: 1, 2, 3, 4, 5; should be -2, -1, 0, 1, 2</div><div>*/</div><div><br></div><div>-----</div><div>
<br></div><div style>1) is really strange and I'm not sure why it's occurring; 2) is due to the internal codes of a factor being integers, and those being passed along to the names. This could be easily fixed by checking if x is a factor and setting the names attribute to be the levels of the input object in that case.</div>
<div style><br></div><div style><div>> sessionInfo()</div><div>R version 3.0.0 (2013-04-03)</div><div>Platform: x86_64-apple-darwin10.8.0 (64-bit)</div><div><br></div><div>locale:</div><div>[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8</div>
<div><br></div><div>attached base packages:</div><div>[1] stats     graphics  grDevices utils     datasets  methods   base     </div><div><br></div><div>loaded via a namespace (and not attached):</div><div>[1] Rcpp_0.10.4 tools_3.0.0</div>
<div><br></div><div style>As always, thanks for all the work on Rcpp. The reason why I'm so invested in the table sugar function is because it's up to 100x faster than the base R table function, and hence is great for 1D summaries of large vectors.</div>
<div><br></div><div style>-Kevin</div></div></div></div></div>