[R] Newbie problems with R and compiled C
Roger Peng
rpeng at stat.ucla.edu
Tue Dec 18 17:22:38 CET 2001
-roger
_______________________________
UCLA Department of Statistics
rpeng at stat.ucla.edu
http://www.stat.ucla.edu/~rpeng
On Tue, 18 Dec 2001, Prof Brian D Ripley wrote:
> > Then I put in a library with files:
> >
> > #include <stdlib.h>
> >
> > void gen(int *n, int *a, int *c, int *m, int *x0, int *x){
> > int i;
> > x[0] = *x0;
> > for (i = 1; i <= *n-1; i++)
> > x[i] = (*a * x[i-1] + *c) % *m;
> > }
> >
> > for the code and the wrapper function:
> >
> > gen <- function(n, a, c, m, x0){
> > .C("gen", x=integer(n),
> > n=as.integer(n),
> > a=as.integer(a),
> > c=as.integer(c),
> > m=as.integer(m),
> > x0=as.integer(x0))
> > }
>
> The order of the args is wrong: it needs to be
>
> .C("gen", as,integer(n), as.integer(a), as.integer(c), as.integer(m),
> as.integer(x0), x = integer(n)$n
>
> I think.
Prof. Ripley is right, the order of the arguments is incorrect. But I
think, what you want is:
.C("gen", as,integer(n), as.integer(a), as.integer(c), as.integer(m),
as.integer(x0), x = integer(n)$x
since x is where you're storing the random numbers, no?
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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