[Rcpp-devel] How to call a function from an R package in cpp code

Dirk Eddelbuettel edd at debian.org
Tue Oct 11 13:02:00 CEST 2016

On 11 October 2016 at 15:54, Amina Shahzadi wrote:
| I want to use dgev(x,shape=1,scale=1,location=0,log=FALSE) function of an R
| package "FAdist" in the framework of Rcpp. How can I call that?
| For example for the Poisson distribution which is basic function of R I have
| written the following code.
| #include <Rcpp.h>
| using namespace Rcpp;
| //[[Rcpp::export]]
| NumericVector poiss(NumerixVector x, double lam, int give_log)
| {
|         return R::dpois(x, lam, give_log);
| }

First off, your example makes no sense. You probably want to call Rcpp::dpois
as you work on a _vector_ x. Rcpp::dpois closely corresponds to what you have
in R as dpois() __because we an underlying function we can call to do the

You have said nothing about how FAdist::dgev() is implemented. The answer
will depend on that, and there is nothing we can say as it is stated.

Not everything you see in any given R package as underlying C++ code.


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

More information about the Rcpp-devel mailing list