Something is wrong with you, or maybe I completely misunderstand the question.
First, sample() accepts whole vectors, in fact it is a pattern.
Secondly, you did not use your arguments at all.
Here is the edited version:
// [[Rcpp::depends(RcppArmadillo)]] #include <RcppArmadilloExtensions/sample.h> #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] IntegerVector sampleDemo(IntegerVector iv) { // removed unused arguments IntegerVector is = RcppArmadillo::sample<IntegerVector>(iv, 3, false); return is; } /*** R set.seed(42) sampleDemo(c(42L, 7L, 23L, 1007L)) */
and this is his conclusion:
R> sourceCpp("/tmp/soren.cpp") R> set.seed(42) R> sampleDemo(c(42L, 7L, 23L, 1007L)) [1] 1007 23 42 R>
Edit: And while I wrote this, you yourself answered ...
source share