[Rcpp-devel] Attribute does not compile with 'compileAttributes' but with 'sourceCpp'

Simon Zehnder szehnder at uni-bonn.de
Fri Nov 1 15:01:20 CET 2013


Dear Rcpp::Users and Rcpp::Devels,

I get a weird exception when I try to compile an attribute in one of my packages:

compileAttributes("/Users/simonzehnder/git/mmstruct/mmstruct/")
R(6256,0x7fff79ad9310) malloc: *** error for object 0x7fff7ac48330: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

If I instead use the sourceCpp function all works fine:

sourceCpp("/Users/simonzehnder/git/mmstruct/mmstruct/src/testing.cpp”)
testfunction_cc(c(0,0,0), list(trades = rnorm(10), T = 360))
[1] 0.000000e+00 3.509927e-05 1.169976e-05

The function in my file is actually pretty simple (and its the only one):

#include<Rcpp.h>

// [[Rcpp::export]]

Rcpp::NumericVector testfunction_cc(Rcpp::NumericVector par, 
        Rcpp::List list) 
{
    const unsigned int K        = par.size();
    Rcpp::NumericVector trades  = list["trades"];
    const unsigned int T        = list["T"];
    double tmp = mean(trades)/T;
    std::vector<double> startp(K);
    startp[0] = 0.0;
    startp[1] = tmp * 0.75/2;
    startp[2] = tmp * 0.25/2;

    return Rcpp::wrap(startp);
}

At this moment I am a little perplexed. Where should I search for a possible error? What are things to try out? 

Best

Simon



More information about the Rcpp-devel mailing list