[Rd] Problems when linking to R shared library

From: John Maddock <john_at_johnmaddock.co.uk>
Date: Thu, 31 May 2007 19:04:25 +0100


Folks,

I'm fairly sure that I'm doing something stupid, but I'm getting a few really strange results from *some* of the distributions, but by no means all,
when I link directly to the R shared library.

I've tried this on both Windows with the precompiled Mingw binary of R-2.5.0 (compiling my code with MinGW-3.4.2), and by building R-2.5.0 on Mandriva Linux with gcc-3.4.4 and --enable-R-shlib. The actual code is at the end of the message, but the main cases are:

std::cout << pf(1.5, 2.0, 3.0, 1, 0) << std::endl;

Outputs 1, expect 0.646447

std::cout << pchisq(1.5, 2.0, 1, 0) << std::endl;

Outputs 1, expect 0.527633

std::cout << pgamma(1.5, 2.0, 3.0, 1, 0) << std::endl;

Outputs 1, expect 0.090204

std::cout << ppois(2.0, 5.0, 1, 0) << std::endl;

Outputs 0, expect 0.124652

std::cout << qchisq(0.5, 2.0, 1, 0) << std::endl;

Outputs -0.61379, expect 1.38629

std::cout << qgamma(0.5, 2.0, 3.0, 1, 0) << std::endl;

Outputs 0.0282703, expect 5.03504

I should stress that within the R environment, I *do* get the values I expect: though sometimes the arguments need adjusting as the C functions have slightly different argument lists from the R versions.

Also:

std::cout << qpois(0.5, 5.0, 1, 0) << std::endl;

Seems to go into an infinite loop inside qpois, while:

qbeta(0.1, 1e-5, 1e-5, 1, 0);

Raises an access violation inside R: although I should stress that all other beta quantiles I've tested come out OK.

Anyway, hopefully you can just tell me what an idiot I am :-)

Thanks in advance for any help you can give,

John Maddock.

The complete source code is:

#include <iostream>
#include <iomanip>

extern "C" {
#include "Rmath.h"
}

int main(int argc, const char** argv)
{

  std::cout << pf(1.5, 2.0, 3.0, 1, 0) << std::endl;
  std::cout << pchisq(1.5, 2.0, 1, 0) << std::endl;
  std::cout << pgamma(1.5, 2.0, 3.0, 1, 0) << std::endl;
  std::cout << ppois(2.0, 5.0, 1, 0) << std::endl;
  std::cout << qchisq(0.5, 2.0, 1, 0) << std::endl;
  std::cout << qgamma(0.5, 2.0, 3.0, 1, 0) << std::endl;
  //std::cout << qpois(0.5, 5.0, 1, 0) << std::endl;   return 0;
}

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 31 May 2007 - 18:11:35 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 01 Jun 2007 - 05:33:58 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.