[R] R mathlib

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jun 22 16:32:06 CEST 2004


The Rmath package does not have runif (nor does it say it has).  It does 
(at least in the R sources) have a README file, and it always helps to 
read READMEs.

On Tue, 22 Jun 2004, Dirk Eddelbuettel wrote:

> On Tue, Jun 22, 2004 at 05:41:53PM +0400, Timur Elzhov wrote:
> > Hello, dear R experts!
> > 
> > I run R on Debian 'sarge' platform. There is 'r-mathlib' package in
> > Debian distribution, which is described as:
> >    $ dpkg --status r-mathlib
> >    ...
> >    This packages provides the libRmath shared and static libraries which
> >    can be called from standalone C or C++ code.
> > 
> > Well, I use runif() function in test_runif.c:
> > 
> > #include <Rmath.h>
> > 
> > main()
> > {
> > // ...
> >     printf("%f\n", runif(0, 1));
> > }
> > 
> > and compile it:
> > 
> > $ gcc -I/usr/lib/R/include -lRmath -lm -o test_runif test_runif.c 
> >  /tmp/ccmICWeD.o(.text+0x2d): In function `main':
> >  : undefined reference to `Rf_runif'
> >  collect2: ld returned 1 exit status
> > 
> > Replacing `-lm' with `-lR' solves the problem. So, I need libR.so anyway?
> 
> I haven't glanced at the docs in a while, but I think you premiser is wrong.
> The standalone library libRmath from the r-mathlib package offers
> probability functions and other 'utilities', but not random number
> generators which are stateful, can be selected and switched etc pp which
> leads to the requirement of libR, and with that come possible requirements
> for R initializations.
> 
> Whereas the standalone library really is that:
> 
> edd at basebud:~> head /usr/share/doc/r-mathlib/examples/test.c 
> /*
>  *  Mathlib : A C Library of Special Functions
>  *  Copyright (C) 2000  The R Development Core Team
>  *
>  *  This program is free software; you can redistribute it and/or modify
>  *  it under the terms of the GNU General Public License as published by
>  *  the Free Software Foundation; either version 2 of the License, or
>  *  (at your option) any later version.
>  *
>  *  This program is distributed in the hope that it will be useful,
> edd at basebud:~> tail /usr/share/doc/r-mathlib/examples/test.c 
> #define MATHLIB_STANDALONE 1
> #include <Rmath.h>
>  
> int
> main()
> {
> /* something to force the library to be included */
>     qnorm(0.7, 0.0, 1.0, 0, 0);
>     return 0;
> }
> edd at basebud:~> gcc -o /tmp/foo /usr/share/doc/r-mathlib/examples/test.c -lm -lRmath
> edd at basebud:~> /tmp/foo
> edd at basebud:~> 
> 
> So it compiles and builds standalone as promised.
> 
> Dirk
> 
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list