[Rcpp-devel] caught segfault solved

Ricardo Silva rsilvabioinfo at usp.br
Sat Oct 13 00:43:21 CEST 2012


Hello all,

first of all, I would like to apologize to ask questions without
exhaustively searching for the answer by myself. Dirk and Garrett were very
nice to run my code, even when haven't did my homework. I promise I got the
lesson and I will work harder before posting another question...

I would like to report the mistake, maybe some beginner could benefit of
this.

Following Dirk's idea I've isolated the problem, running small chunks of
code, I was doing


call.gibbs <- cxxfunction(

 signature(x="numeric", y="numeric",N="interger", w="numeric", p="numeric",
*fun= "function" *) ,...


 where *fun* was the R's sample function

                       pos = as<int>(f(ya.size(), 1, "FALSE",  betaP)) - 1;


as R was reporting a vector position I've subtracted 1 to match vector
positions on the rest of the code. Worked well, I even created a package
with the prototype.  importing R's sample function as an example in *
Rcpp-introduction*.

I don't  know what happened later...

I found a similar way to find the same answer I was searching with sample
function, one I could easily code in c++


 prob <- c(0.03, 0.001, 0.15, 0.0001, 0.30, 0.27, 0.2489)

# the way I was used to do

table(sample(1:7, 100, replace=TRUE, prob=prob))

# the new way

table(sapply(1:100, function(x) which(cumsum(prob)>runif(1))[1]))


hope it could be useful to some one, I spent two days to figure it out.

Ricardo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20121012/ed662c21/attachment.html>


More information about the Rcpp-devel mailing list