Valentin Ruano Valentin Ruano - 1 year ago 81
R Question

How to call dpois_raw C stats routine from R

I'm trying to figure out a way to call stats package's "dpois_raw" routine rather than the "dpois" wrapper using .Call .External or whatever means.

"dpois_raw" is not listed in the package environment

nor when I do
so I am probably out of luck, but I wonder whether someone R/C expert knows of a workaround.

Answer Source

The dpois_raw routine is provided by the Rmath.h header, and it doesn't appear to actually be exposed as part of the stats package (or otherwise); however, it is made available to C / C++ code through the Rmath.h header.

The simplest way to expose it would be with your own C / C++ code exposing that code, e.g. (code stub)

#include <R.h>
#include <Rmath.h>

SEXP my_dpois_raw(<...>) {
   double result = dpois_raw(<...>);
   return result;

This routine would then be callable from R with something like

.Call("my_dpois_raw", <...>)

See Hadley's r-pkgs section on using compiled code in R packages for some more information on including C / C++ code in an R package.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download