Forum OpenACS Q&A: Embedding R in Postgress

Collapse
Posted by Ulka Rathi on
Please visit at http://www.omegahat.org/RSPostgres/
and let me know if it is possible to do in TCL.

Any comments are welcome.

Collapse
Posted by Andrei Popov on
What exactly?  What the page describes is how a new proc language can be added to Postgres -- what does it have to do with TCL?
Collapse
Posted by Cheng-Yi Hsu on
Hi:
Are you trying to integrate statistical language R in OpenACS environment ?
Collapse
Posted by Ulka Rathi on
Yes I would like to integrate R Embedded Postgress in openacs environment. And would like to know if that is possible.
Collapse
Posted by Andrew Piskorski on
Ulka, I have not heard of anyone taking Duncan Long's work Embedding R in Postgres and actually using it in a Production setting. But if you have, I'd be very interested! Please let us know what you find out...

You may want to ask if anyone has picked up Long's work on the R database special interest group mailing list. The list has almost no traffic, but some very high-powered R people (e.g., Brian D. Ripley) do subscribe and respond.

Also, back in October 2001, Roberto and Don pointed out that Long was probably mistaken in believing that R needs to be thread safe when embedded inside Postgres - it doesn't. On the other hand, if you instead wanted to embed R inside AOLserver, like others have done for Python, Java, Standard ML, and Perl, then it would need to be thread-safe.

If you can get R working reliably (perhaps it does already - I don't know) in either Postgres or AOLserver, or both, then you'll be able to use it nicely in an OpenACS environment. Once you do that, there's nothing particularly special about OpenACS that would either prevent or help you from using R however you want.

If your needs are simpler, you can always simply spawn R processes from Tcl (or perhaps even as CGI scripts). I haven't tried that with R (yet), but I've seen it done with S-Plus. S-Plus makes this slightly annoying because you have to do a bunch of setting of environemnt variables and stuff to play nice with S-Plus's "workspaces", but it's definitely practical if you just need to run some S calculations from Tcl.

By the way, Ulka, what sort of uses to you expect to put R to in your OpenACS environment? I'm curious...

Collapse
6: PL/R for PostgreSQL (response to 1)
Posted by Andrew Piskorski on
An update: Joe Conway <mail@joeconway.com> said on the Postgres hackers list that he's about to release PL/R, an implementation of R as a PosgreSQL procedural language.

This is similar to but different than Duncan Lang's earier work Embedding R in Postgres. In addition to the Postgres hackers email above, Joe also had this to add about PL/R:

You might say it was inspired by Duncan's work, but not really related/derived from it. He approached the problem from a very "R centric" point of view, and I from a very "PostgreSQL centric" point of view (not surprising given our respective backgrounds). PL/R does however rely on R's ability to be embedded as a shared library, and I believe Duncan was the primary driver of that (based on what I've found browsing around).
Collapse
Posted by Stan Kaufman on
This is very, very cool. Can't wait to have a look at this!
Collapse
Posted by Roberto Mello on
This is awesome. Having used R for a statistics class, I can just imagine the possibilities of neat stuff one will be able to do straight from PG and integrate into OpenACS.

Another triumph for free/open source software.

-Roberto

Collapse
9: Re: PL/R for PostgreSQL (response to 6)
Posted by Andrew Piskorski on
More PL/R links: PL/R homepage, and page on GBorg.
Collapse
10: Re: PL/R for PostgreSQL (response to 9)
Posted by Cheng-Yi Hsu on
I have create a nsR.c module for aolserver with limit function, since R can compile as a share library, so I can provide loadable module for aolserver. Now I can call R function from tcl. I do not have enough resource to develop the module, if anyone feel interesting , you can take the source code an continue improve it. you can ferform function call like this:
set x [nsR log1p 1.5]
set x [nsR expml 2]
set x [nsR gamma 10]

Collapse
11: Re: PL/R for PostgreSQL (response to 10)
Posted by Andrew Piskorski on
Cheng-Yi, that's interesting. I don't think I'll have the need or time to play with your nsR.c stuff anytime soon, but maybe you can upload it to file-storage or something in case others are interested?

Btw, what did you do about thread safety? Last I heard I thought R was not thread-safe, but maybe it is now?

Collapse
12: Re: PL/R for PostgreSQL (response to 11)
Posted by Cheng-Yi Hsu on
In fact, what I do is just a POC, I follow the document Writing R Extensions and AOLserver C Module Example , R provide many numerical/stat function for C and FORTRAN program , maybe R was not thread-safe, but I "guess" the function call are thread-safe. This is the first step, what I need is pass a tcl list to nsR, and do some plotting job and return the image without fork a new R process.
Collapse
13: mod_R for Apache (response to 1)
Posted by Andrew Piskorski on
FYI, someone's recently created mod_R, which embeds R into Apache 2.0. No design docs that I could find, but the readme implies that it only works with the prefork Apache MPM, which makes sense as R isn't yet thread-safe. At first glance, the functionality mod_R offers seems to be extremely limited, so limited I'm not even sure why its creator even wants to use it; but then I don't know much about Apache.