Setzer.Woodrow@epamail.epa.gov
2001-Dec-13 13:49 UTC
[R] R-1.4.0: how to use getSymbolInfo()?
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)? Thanks. R. Woodrow Setzer, Jr. Phone: (919) 541-0128 Experimental Toxicology Division Fax: (919) 541-5394 Pharmacokinetics Branch NHEERL MD-74; US EPA; RTP, NC 27711 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Setzer.Woodrow@epamail.epa.gov
2001-Dec-13 16:19 UTC
[R] R-1.4.0: how to use getSymbolInfo()?
Welll, getSymbolInfo() returns a list that includes an external pointer object. I guess my question is, how to unwrap it in the c code so that I can use it as (*f)()? R. Woodrow Setzer, Jr. Phone: (919) 541-0128 Experimental Toxicology Division Fax: (919) 541-5394 Pharmacokinetics Branch NHEERL MD-74; US EPA; RTP, NC 27711 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Setzer.Woodrow@epamail.epa.gov
2001-Dec-17 14:34 UTC
[R] R-1.4.0: how to use getSymbolInfo()?
Thanks, Duncan. That is exactly what I was looking for! and yes, it is getNativeSymbolInfo(); sorry for the confusion. R. Woodrow Setzer, Jr. Phone: (919) 541-0128 Experimental Toxicology Division Fax: (919) 541-5394 Pharmacokinetics Branch NHEERL MD-74; US EPA; RTP, NC 27711 Duncan Temple Lang <duncan at research.bell To: Woodrow Setzer/RTP/USEPA/US at EPA -labs.com> cc: r-help at stat.math.ethz.ch Subject: Re: [R] R-1.4.0: how to use getSymbolInfo()? 12/15/01 11:10 AM Setzer.Woodrow at epamail.epa.gov wrote:> > Welll, getSymbolInfo() returns a list that includes an externalpointer> object. I guess my question is, how to unwrap it in the c code sothat> I can use it as (*f)()?Hi Woodrow, I have been away from the office for the past few days, so didn't get your mail until now. Just in case you haven't got an answer, here is one. As you correctly point out, what you need is a way to unwrap the external pointer. The C routine R_ExternalPtrAddr() will do this for you. Your situation is one of the contexts that motivated adding the reflectance information about native symbols. We can pass R functions or "NativeSymbol" objects and have C code handle them appropriately. I put together two examples of the mechanism and they are available at http://cm.bell-labs.com/stat/duncan/RSymbolInfo.tar.gz The file basic.c shows what you need to do. chandler.c shows how to handle either an R function or a NativeSymbol object. BTW, it is getNativeSymbolInfo() rather than getSymbolInfo(), isn't it? Duncan.> > R. Woodrow Setzer, Jr.Phone:> (919) 541-0128 > Experimental Toxicology Division Fax: (919) > 541-5394 > Pharmacokinetics Branch > NHEERL MD-74; US EPA; RTP, NC 27711 > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-> r-help mailing list -- Readhttp://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> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ -- _______________________________________________________________ Duncan Temple Lang duncan at research.bell-labs.com Bell Labs, Lucent Technologies office: (908)582-3217 700 Mountain Avenue, Room 2C-259 fax: (908)582-3340 Murray Hill, NJ 07974-2070 http://cm.bell-labs.com/stat/duncan -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._