[R] R-1.4.0: how to use getSymbolInfo()?

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Dec 13 16:19:05 CET 2001

Setzer.Woodrow at epamail.epa.gov writes:

> I have a package that solves systems of ordinary differential equations
> coded as an R function (odesolve, on CRAN).  The function is passed to R
> code, and c and Fortran code called by it uses lang4() and eval() to
> evaluate the R function inside a compiled c function to use in a
> compiled ODE solver.  This works quite well, but can be slow.
> I'd like to be able to supply the name of a compiled function,
> dynamically loaded into the current session, and pass either the name of
> the function or a pointer to it to my R code, which would then pass it
> down to the compiled code to use in the ode solver directly.
> Since getSymbolInfo() (new in 1.4.0) returns a pointer to the requested
> loaded function, it would seem to be part of the answer to my problem
> (when I asked this question some time ago, I was warned away from using
> the internal R_FindSymbol() (declared in Rdynload.h) as being
> potentially unstable).  However, I cannot figure out how to pass the
> pointer through .Call or .External.  Is this possible, or should I pass
> a string through to the compiled code, and find the pointer on that side
> (and how to do that)?

We might want to take a more abstract view of this. Suppose, as part
of your dyn.loadable module, you also have a small wrapper function
that returns one of Luke's external pointer objects
(http://www.stat.umn.edu/~luke/R/references.html). That should be easy
to do via a .Call interface. Then in odesolve, if you get passed a
pointer object,  you unwrap it and then you can do (*f)(x) to your
heart's content.

Does this sound right?

   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