[R] API question (embedding R)

Duncan Murdoch murdoch at stats.uwo.ca
Tue Oct 27 10:30:25 CET 2009


On 26/10/2009 6:56 PM, Bernd Kreuss wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hello list,
> 
> i want to access R from a Pascal program. Basically i only need to be
> able to
> 
> * start the engine / the interpreter (and keep it running)
> * pass strings to it (R code) that should be parsed and executed
> * get floats or vectors of floats into R and assign them to R variables
> * read the contents of variables and get them back into my Pascal
> program. (I dont need this for all possible data structures, just floats
> and maybe vectors of floats would be sufficient)
> 
> At the moment i have something running that does exactly this via Python
> and the rpy bindings, this works but is horribly complicated to install
> because of all the needed dependencies. It works like this: the pascal
> program loads the python interpreter (this API is extremely simple, i
> can get floats and lists of floats in and out of python variables and
> have it compile and execute python code), the pascal program then lets
> python import the rpy bindings, put the data into python variables, from
> there (by executing python code) move the data into R variables and then
> finally execute R code (by executing python code that would call into R
> to execute R code contained in a string literal). Getting the results
> back goes a similar way.
> 
> Now i want to make this more straightforward, i need a way to directly
> access the R interpreter just like i can already access the python
> interpreter. Using the python interpreter from pascal is a child's play,
> you really only need to import a handful of functions from the dll and
> nothing else, you just call Py_Initialize() and then you can call
> PyRun_SimpleString() as often as you want and thats basically all! No
> need to convert the whole C header file to pascal, it all fits more or
> less into 5 lines of pascal declarations.
> 
> I couldn't find an easy documentation of how i could achieve the same
> thing with R: load the dll, import only a few needed functions (which
> ones do i actually need?) and how to use them. Is there a minimal
> example somewhere? What documents should I read? Maybe i missed
> something important?
> 
> An example would actually be the most important thing, an example tells
> more than thousand words.

You didn't say what platform you're on, but on Windows, it's relatively 
easy to do with R-(D)COM.  I don't know if there's anything similar on 
other platforms, but the R Extensions manual describes how to write a 
new front-end for R.

Duncan Murdoch

> 
> Thanks in advance,
> Bernd Kreuss
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iD8DBQFK5ikSxT6R4jlFoh0RAi8LAJwMiDRVWLZBZp2JYynpCtnS48r25gCgzrLF
> s5hYB20RCr2RuxIPe8EW8ws=
> =erKc
> -----END PGP SIGNATURE-----
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list