[R] transform R to C

Andreas Wittmann andreas_wittmann at gmx.de
Mon Jan 5 14:11:58 CET 2009


Dear R users,

i would like to transform the following function from R-code to C-code and call it from R in order to speed up the computation because in my other functions this function is called many times.


`dgcpois` <- function(z, lambda1, lambda2)
{
  `f1` <- function(alpha, lambda1, lambda2)
     return(exp(log(lambda1) * (alpha - 1) - lambda2 * lgamma(alpha)))
     
  `f2` <- function(lambda1, lambda2)
    return(integrate(f1, lower=1, upper=Inf, lambda1=lambda1, lambda2=lambda2)$value)

  return(exp(log(lambda1) * z - lambda2 * lgamma(z + 1) -
             log(f2(lambda1=lambda1, lambda2=lambda2))))
}


In order to do this i read for example dgamma.c or dpois.c but for my it seems rather cryptic and so i would like get some advice in writing the c-function. First of all i think i cannot call the integrate r-function from c so i have to use the internal c-function of integrate here?

Thanks,

Andreas
--




More information about the R-help mailing list