[R] embedding R?
Peter Dalgaard BSA
p.dalgaard at pubhealth.ku.dk
Sun Feb 11 19:52:43 CET 2001
Aaron J Mackey <ajm6q at virginia.edu> writes:
> int main(int argc, char **argv) {
>
> int n;
> int i[MAXNUM];
>
> for(n = 1 ; n < argc && n <= MAXNUM ; n++) {
> i[n-1] = atoi(argv[n]);
> }
>
> printf("mean: %4.2f\n", R_mean(i, n - 1));
> exit(0);
> }
>
> % gcc -lR mean.c -o mean
> % mean 4 5 6 7
> mean: 5.5
> % exit
>
> Where "R_mean" is calling the R function mean() ???
>
> Any help is appreciated. And I'm not going to worry about graphical
> functions just yet. Just need a pointer or two into the right piece of
> documentation.
This easily gets involved, but:
You can link R as a dynamic library. You'll need to convert C
structures to and from R internal storage form. Some of the
lower-level functions work on C structures directly. There's also the
possibility of building the standalone mathlib.
Much of R sits at the interpreted level, so you'd probably want to be
able to call the parser/evaluator rather than R's internal C code.
There's a rudimentary example of such a thing in the R_eval function
in tcltk.c. (This assumes that the variables you're dealing with are
already known to R, so you'd have to find a way of making that so...).
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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