From Kurt.Hornik@ci.tuwien.ac.at  Mon Jun  9 07:02:18 1997
From: Kurt.Hornik@ci.tuwien.ac.at (Kurt Hornik)
Date: Mon, 9 Jun 1997 08:02:18 +0200
Subject: R-alpha: unif_rand() again
In-Reply-To: <x2u3jf4pvm.fsf@bush.kubism.ku.dk>
References: <199706031445.QAA13652@aragorn.ci.tuwien.ac.at>
 <x2yb8r4t31.fsf@bush.kubism.ku.dk>
 <199706031517.RAA13734@aragorn.ci.tuwien.ac.at>
 <x2u3jf4pvm.fsf@bush.kubism.ku.dk>
Message-ID: <199706090602.IAA32599@aragorn.ci.tuwien.ac.at>

>>>>> Peter Dalgaard BSA writes:

> Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> writes:
>> >> What I need is to call runif() (more precisely, `runif(1, 0, 1)') from
>> >> inside a C function.  Is this possible using call_S?  If so, how?
>> 
>> > Hmm ... Stupid counter-question: Did you study the zfun() function in
>> > $RHOME/demos/dynload/zero.c ? Looks pretty straightforward to me,
>> > except that I have no offhand guess what the 0L argument to call_S is
>> > good for. Peeking at the source should cure that.
>> 
>> I did.  I hoped that something like
>> 
>> static char *func = "runif";
>> 
>> double unif_rand() {
> ...
>> return(result[0]);
>> }
>> 
>> might work, but it does not ...

> Aha. I see, call_R seems to want an SEXP parameter, not a character
> pointer. So some way of converting "runif" into the relevant SEXPREC
> seems to be needed. Something like mkChar() <um, no, that doesn't seem
> to be the way to make a "SEXPsymbol"..> followed by findFun(). Or just
> pass it as a parameter to .C

I see.

Thanks to all who helped.  I now have a working example of unif_rand(),
but I still hope for Ross to come up with something cleaner ...

Trying to map a function name to the function in call_R would be very
nice, in any case.

-k
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel 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-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


R-alpha: unif_rand() again
Kurt Hornik