[Rcpp-devel] how to use functions from other packages

Dirk Eddelbuettel edd at debian.org
Sun Apr 24 04:05:56 CEST 2011


On 23 April 2011 at 20:36, Siddhartha Chib wrote:
| This is likely to be too simple a question perhaps.  How does one use specific
| functions from other packages when working with Rcpp?  For that matter, is it
| possible to use R functions such as optim in Rcpp? 

Yes, sure. I don't think we have a great example though.  

But you could e.g. look at the Rcpp-introduction vignette (now also published
in Vol 40(8) of the Journal of Statistical Software) and look at the examples
for accessing 'rnorm' in Table 1: via Rcpp::Environment and Rcpp::Function,
via Rcpp::Language and (but that is particular to a subset of functions) via
Rcpp sugar.  The Environment and Function route should work for you for just
about any function.

Similarly, and that is becoming my default answer to anything, the several
hundred unit tests have examples that are (by design) 'working'. See eg
runit.Function.R which accesses 'sort()' a couple of times.

Also, the CRAN package minqa by Bates, Mullen, Nash, and Varadhan implements
a (derivative-free) optimisation method using Rcpp, so it may have pointers.
As may my RcppDE which does differential evolution; it even offers access to
objective functions supplied as either R or C++ code.

A concise example would be good.  Maybe another list member has something?

Cheers, Dirk

-- 
Gauss has an Erdos number of -1.
   -- #63 at http://www.gaussfacts.com


More information about the Rcpp-devel mailing list