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 | [email protected] | http://dirk.eddelbuettel.com
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to