[Rcpp-devel] Alternative way of calling R functions within C++

Dirk Eddelbuettel edd at debian.org
Wed Aug 3 21:22:48 CEST 2016


On 3 August 2016 at 11:38, George Vega Yon wrote:
| Thanks for the quick reply! What kind of errors are we talking about? I a new
| run I explicitly caused an error by passing a character vector, and had no
| memory leak (using Valgrind):
| 
| cppFuncall(letters, fun)
| Error in cos(x[1]) : non-numeric argument to mathematical function
| 
| If its not too much to ask, could you give an explicit example in which that
| happens (memory leak)? Just trying to learn here!

You are misreading what Kevin said.  You short ten-line example runs fine.
We are not saying it has an error.

What Kevin explained to you is that in the context of larger programs,
possibly with inputs you don't know yet, some errors may occur. And both
Rcpp:Function() and Rcpp::stop() can recover from that.

Your example cannot.  So by all means use it as a small (local) script if the
few milliseconds matter to you.  But think twice about using it in a larger
context, or about promoting it as a general solution, and understand why we
can't put it into Rcpp as is.

Hth, Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list