[R] trouble using R Mathlib as standalone

Dirk Eddelbuettel edd at debian.org
Mon Jan 14 23:42:33 CET 2002


  "Faheem" == Faheem Mitha <faheem at email.unc.edu> writes:
  Faheem> I am trying to use R's Math library as standalone, as documented in
  Faheem> /src/nmath/standalone. I am using C++ in Debian testing, and the
  Faheem> versions are as follows:
  Faheem> 
  Faheem> ii  g++-3.0        3.0.3-1        The GNU C++ compiler.
  Faheem> ii  r-mathlib      1.4.0-1        `GNU S'  - Standalone R math library
[...]
  Faheem> I get two different errors.
  Faheem> 
  Faheem> The first one I am completely mystified by.

It is just a warning which goes away if you omit -pedantic. It seems to
collide with the header from glibc:

edd at homebud:/tmp> grep log1p /usr/include/Rmath.h /usr/include/bits/mathcalls.h
/usr/include/Rmath.h:#define log1p              Rf_log1p
/usr/include/Rmath.h:double  log1p(double); /* = log(1+x) {care for small x} */
/usr/include/bits/mathcalls.h:__MATHCALL (log1p,, (_Mdouble_ __x));

  Faheem> The second one clearly has to do with the usage of GetRNGstate() and
  Faheem> PutRNGstate() which are correct for use as entry points into the R
  Faheem> executable but no longer correct for standalone usage. 

They do not exist in Rmath.h -- meaning that you cannot call them.

  Faheem> The README in the standalone directory said something about using
  Faheem> the uniform random number generator, but gave no examples so I
  Faheem> didn't understand. Can someone tell me what the correct syntax
  Faheem> should be in this case?

Not sure I understand your question.  The set_seed() function allows to fix a
seed so that that subsequent calls will always get the same sequence of
random deviates.  So a simple example which works is

edd at homebud:/tmp> cat fm.cc
#include <iostream>
#include <cstdlib>
#include <cmath>

#define MATHLIB_STANDALONE 1
#include <Rmath.h>

int main(void)
{
  for (int i=0; i<3; i++) {
    set_seed(123,456);          // no claims that these are good seeds
    double u = unif_rand();
    cout << "Got " << u << endl;
  }
}
edd at homebud:/tmp> g++ -Wall -o fm fm.cc -lRmath
edd at homebud:/tmp> ./fm
Got 0.384571
Got 0.384571
Got 0.384571

Hope this helps,  Dirk

-- 
Good judgment comes from experience; experience comes from bad judgment. 
							    -- F. Brooks
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list