Skip to content
Prev 5022 / 10988 Next

[Rcpp-devel] Sample function(s) for inclusion in RcppArmadillo

I'm working on writing runit tests for the previously-discussed
sample, and I just hit my competence threshold dealing with
inst/include.
As discussed, the (overloaded) sample() functions are to be called
only from user C++ code and are thus not exposed to R.
This means that the function definitions should go in inst/include, correct?

I don't really know what I'm doing here.  If someone could recommend a
good reference for namespace control, headers, and R-package specific
issues I'd be grateful.   Details follow:

I'm trying to get the following test function to use RcppArmadillo's
definition of sample, and the compiler never finds it:
    require(Rcpp)
    cppFunction( code='
        IntegerVector sample_int_noprob( IntegerVector x, int size,
bool replace) {
            RNGScope scope;
            IntegerVector ret = RcppArmadillo::sample(x, size, replace);
            return ret;
        }',
    depends='RcppArmadillo'
    )

I tried placing the definition of sample in
RcppArmadillo/inst/include/sample.h.
        using namespace Rcpp;
        template <class T>
        T sample(const T &x, const int size, const bool replace,
NumericVector prob_ = NumericVector(0) ) {
            // Templated sample -- should work on any Rcpp Vector
         ...
        }

I've tried to use RcppArmadilloWrap.h as an example, using:
namespace Rcpp{
    namespace RcppArmadillo{
    ...
    }
}

best,
Christian
On Thu, Nov 15, 2012 at 5:35 AM, Dirk Eddelbuettel <edd at debian.org> wrote:

  
    
Message-ID: <CADNH-PuB4JfRJQXQu8VMuETYYwuqL6+BvBFfsM+TbFjymvCv3g@mail.gmail.com>
In-Reply-To: <1e09aa3a511a49a4973f2400273495dd@BLUPRD0711HT005.namprd07.prod.outlook.com>