Hi,
I've been trying to get this working for ages, but it causes R to hang.
Here is my C code saved as test1.c
# include <R.h>
# include <Rmath.h>
void test1 (double *x, double *result)
{
result[0] = rgamma(*x, 2.0);
}
This was compiled using R CMD SHLIB test1.c & loaded in R using:
dyn.load("test1.dll")
out <- .C("test1",x=as.double(2),random=double(1))
R then hangs
However, if I change "rgamma" in the above to be "rnorm" or
"runif",
everything works just fine. I'm not sure if it matters, but the function
'rgamma' under R works OK.
I'm running Windows XP & I followed the instructions at
http://cran.r-project.org/doc/manuals/R-admin.html#Windows-standalone
after building R from source.
Thanks,
Steve
G'day Steve, On Tue, 20 Jul 2010 17:20:49 +0930 Steve Pederson <stephen.pederson at adelaide.edu.au> wrote: I suggest to insert the following two lines (untested as I usually don't work on Windows):> # include <R.h> > # include <Rmath.h> > void test1 (double *x, double *result) > {GetRNGstate();> result[0] = rgamma(*x, 2.0);PutRNGstate();> } >[...]> I'm running Windows XP & I followed the instructions at > http://cran.r-project.org/doc/manuals/R-admin.html#Windows-standalone > after building R from source.But you didn't follow the instructions of Section 6.3 in the "Writing R Extensions manual. :) http://cran.r-project.org/doc/manuals/R-exts.html#Random-numbers HTH. Cheers, Berwin ========================== Full address ===========================Berwin A Turlach Tel.: +61 (8) 6488 3338 (secr) School of Maths and Stats (M019) +61 (8) 6488 3383 (self) The University of Western Australia FAX : +61 (8) 6488 1028 35 Stirling Highway Crawley WA 6009 e-mail: berwin at maths.uwa.edu.au Australia http://www.maths.uwa.edu.au/~berwin