<div dir="ltr">Hi everyone,<div><br></div><div>I am using Rcpp to develop my own package and one of my functions calls back into R for a given amount of iterations. To speed up the process, I wanted to use Rcpp::unwindProtect. However, I couldn't find on Rcpp's documentation what is the correct way to use this plugin. Therefore, I would like to ask you for some guidance, if possible.</div><div dir="ltr" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><span><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><i></i><br></div></div><div>Reproducible toy example:</div><div><br></div><div>````````````````</div><div>require(Rcpp)<br>Rcpp::cppFunction("<br>  NumericVector test_f(NumericMatrix x, Function f) {<br>    NumericVector out(x.ncol());<br>  <br>    for (int iter = 0; iter < x.ncol(); iter++) {<br>      out[iter] = as<double>(f(x(_ , iter)));<br>    }<br>    <br>    return out;<br>  }<br>")<br><br>x <- matrix(1.2:9.2, 3, 3)<br><br>colSums(x)<br>f <- function(x) sum(x)<br>test_f(x, f)<br><br>require(rbenchmark)<br>rbenchmark::benchmark("R1"=colSums(x),<br>                                        "R2"=test_f(x, f),<br>                                        replications=10000)<br></div><div>````````````````<br></div><div dir="ltr"><br></div><div>Best,</div><div>Vithor</div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></span></div></div></div></div></div>