[R] trouble using R Mathlib as standalone

About this list Date view Thread view Subject view Author view Attachment view

From: Dirk Eddelbuettel (edd@debian.org)
Date: Tue 15 Jan 2002 - 09:42:33 EST


Message-id: <15427.24281.32448.632738@sonny.eddelbuettel.com>


  "Faheem" == Faheem Mitha <faheem@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@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@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@homebud:/tmp> g++ -Wall -o fm fm.cc -lRmath
edd@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@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Thu 17 Jan 2002 - 11:10:11 EST