[Rcpp-devel] Problems wrapping stl::vector<int>
    Dirk Eddelbuettel 
    edd at debian.org
       
    Fri Jan  3 19:11:14 CET 2014
    
    
  
On 3 January 2014 at 11:50, Dirk Eddelbuettel wrote:
| On 3 January 2014 at 11:42, Hadley Wickham wrote:
| | Another solution is to rely on Rcpp's auto-wrapping smarts:
| | 
[...] 
| 
| Nope.
My bad.  I had by oversight mixed return types and within-function types. If
you do it properly it works with either std::vector<int> or IntegerVector, as
it has for a long time.
Better version below.
Dirk
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
std::vector<int> test1(){
    std::vector<int> a;
    a.push_back(1);
    a.push_back(2);
    a.push_back(3);
    return a;
}
// [[Rcpp::export]]
IntegerVector test2(){
    IntegerVector a(3);
    a[0] = 1;                   // push_back() not rec'd on Rcpp vectors
    a[1] = 2;
    a[2] = 3;
    return a;
}
-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
    
    
More information about the Rcpp-devel
mailing list