[R] using Rmath in c-functions of R packages

Martin Maechler maechler at stat.math.ethz.ch
Wed Apr 22 11:54:47 CEST 2009


>>>>> "VM" == Volodymyr Melnykov <volmeln at iastate.edu>
>>>>>     on Tue, 21 Apr 2009 21:42:44 -0500 writes:

    VM> On Tue, 21 Apr 2009 21:49:36 -0400
    VM> Duncan Murdoch <murdoch at stats.uwo.ca> wrote:

    >> On 21/04/2009 9:39 PM, Volodymyr Melnykov wrote:
    >> > Dear all,
    >> > 
    >> > We have created an R package and submitted it to C-RAN. The package
    >> > includes several C functions that use Rmath library. The package
    >> > cannot be installed on a computer where -lRmath is not found. We
    >> > were suggested to do a configure test for this but I am not really
    >> > sure how to do this and where to read about this. What is a usual
    >> > way to deal with R packages with c-functions using Rmath?
    >> 
    >> I thought that the functions in libRmath are extracted from R, which 
    >> packages normally link to without any special effort.  You only need 
    >> Rmath if you are writing a standalone C program, not if you are
    >> writing an R package.
    >> 
    >> Duncan Murdoch
    >> 

    VM> Thank you for your response.
    VM> I need c-functions because they are much faster than their R versions.
    VM> In my c-functions, I use rnorm(), rgamma() and other functions like
    VM> these. 

Sure!  and Duncan is 100% correct that there's no need at all to
use Rmathlib which *is* for standalone applications and not for
R packages.

    VM> I am not sure how I would do this without Rmath.

(Re)read "Writing R Extensions".
The math functions are (almost) all part of the exported API!

The relevant chapter in the extensions manual is currently called
    'The R API: entry points for C code'

Regards,
Martin Maechler, ETH Zurich


    VM> Thanks,
    VM> Volodymyr




More information about the R-help mailing list