I am running R 2.15.2 and Rcpp 10.4 (upgraded a few days ago) on RedHat.
When I call the qgamma function in my C++ program compiled via make, it returns 0, but qnorm in the same program returns the correct value (source to follow.) When I call it via a cppFunction compile, I get the right answer.
C++ source:
#include <iostream>
using namespace std;
#include <Rcpp.h>
int main() {
cout << R::qnorm(0.3, 1.0, 1.0, 1, 0) << endl;
cout << R::qgamma(0.3, 5.0, 5.0, 1, 0) << endl;
return 0;
}
and the associated compile messages and execution:
[jbowma1@smartrepl-app00 src]$ make test
g++ -I/usr/include/R -I/usr/lib64/R/library/Rcpp/include -L/usr/lib64/R/lib -lR -L/usr/lib64/R/library/Rcpp/lib -lRcpp -Wl,-rpath,/usr/lib64/R/library/Rcpp/lib -o test test.cpp
[jbowma1@smartrepl-app00 src]$ ./test
0.475599
0
[jbowma1@smartrepl-app00 src]$
The problem of course being that "0" out in the second line of the output above.
Now for the cppFunction version:
> foosrc <- "double foo() {return R::qgamma(0.3, 5.0, 5.0, 1, 0);}"
> bar <- cppFunction(foosrc)
> bar()
[1] 18.16805
(Same computer, naturally, this one executed in RStudio.)
Note that if just calling qgamma
from the R prompt, the third parameter needs to be inverted (=0.2 in this example) to get the same answer.
I'd suspect I'd messed up my makefile, which is actually largely copied from the RcppExamples directory, if it were not for the fact that qnorm
works. dgamma
also works, but pgamma
does not. Other distributions, e.g., the negative binomial, also work.
Any suggestions would be greatly appreciated!