[Rcpp-devel] problem with sample() implemented in Rcpp/RcppArmadillo

Christian Gunning xian at unm.edu
Sat Oct 27 14:13:42 CEST 2012


> I am very new to c++ so I apologize in advance if this is a stupid question:

I ran into this myself when I started using Rcpp  -- it's a good
question.  The R API is extensive, but it's vanilla C and doesn't
handle vectors (and you already know how to sample() a scalar,
right?).

> For a larger analysis I am trying to implement the R function sample() in c++ via RcppArmadillo.

There's a non-trivial penalty for reaching back into R for functions
that aren't exported via the API (e.g. "Rcpp::Function sample =
base["sample"];").  Rcpp Vectors are STL containers, and many folk
have asked the same questions wrt the STL.  There's some good
background reading here:
http://stackoverflow.com/questions/6942273/get-random-element-from-container-c-stl

Christian
-- 
A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!


More information about the Rcpp-devel mailing list