On Mon, 2008-10-20 at 09:55 -0700, Eric Bell wrote:
> I want to be able to call R from python scripts that are being executed
> via lib-apache2-mod-python. Should this be doable?

In theory, yes.
It might have limited testing, still.

> My python script can access some R functionality but it is very limited.
> It *appears* that only the functionality in the base R package is being
> loaded.
>         
>         from mod_python import apache
>         

# is the line below needed at ?
>         import rpy2
# try adding here:
import rpy2.rinterface as ri
ri.set_initoptions(('rpy2', '--verbose', '--vanilla', '--no-save'))

# and run the rest, looking at what the output is...
# (I don't think it will help but well, one never knows).

Otherwise, there might also be entanglements when the apache process is
trying to access R files (libraries) located in directories where is not
configured to go (just a wild guess).


Let us know what is happening.



L.

>         from rpy2 import robjects
>         
>         import math
>         import array
>         
>         def handler(req):
>               r = robjects.r
>         
>               r("y <- (1:10)")
>               r("x <- (1:10)")
>         
>               r('jpeg("/var/www/apache2-default/images/testplot.jpg")')
>               #r.plot(r.runif(10),y,xlab="runif",ylab="foo/bar",col="red")
>         
>               #r._dotter = True
>               #r.dev_off()
>         
>         
>               req.content_type = 'html'
>               req.write("<HTML>")
>               req.write("<BODY>")
>         
>                 req.write("Hello beautiful World!<BR>")
>         
>               req.write('<img src="/apache2-default/images/test123.jpg" />')
>         
>               req.write("</BODY>")
>               req.write("</HTML>")
>         
>                 return apache.OK
> 
> 
> When I access the page, mod_pthon generates the following error
> information:
> 
>         Traceback (most recent call last):
>         
>           File "/usr/lib/python2.5/site-packages/mod_python/importer.py", 
> line 1537, in HandlerDispatch
>             default=default_handler, arg=req, silent=hlist.silent)
>         
>           File "/usr/lib/python2.5/site-packages/mod_python/importer.py", 
> line 1229, in _process_target
>             result = _execute_target(config, req, object, arg)
>         
>           File "/usr/lib/python2.5/site-packages/mod_python/importer.py", 
> line 1128, in _execute_target
>             result = object(arg)
>         
>           File "/var/www/apache2-default/test_python/mptest.py", line 16, in 
> handler
>             r('jpeg("/var/www/apache2-default/images/testplot.jpg")')
>         
>           File "/usr/lib/python2.5/site-packages/rpy2/robjects/__init__.py", 
> line 501, in __call__
>             res = self.eval(p)
>         
>           File "/usr/lib/python2.5/site-packages/rpy2/robjects/__init__.py", 
> line 381, in __call__
>             res = super(RFunction, self).__call__(*new_args, **new_kwargs)
>         
>         RRuntimeError: Error in eval(expr, envir, enclos) : could not find 
> function "jpeg"
>         
> ------------------------
> 
> If I modify my python script to call the R library() function, I get a
> different error message.
> 
>         def handler(req):
>                 r = robjects.r
>         
>                 r("library()")
>               .
>               .
>               .
>         
> Generates:
> 
>         Traceback (most recent call last):
>         
>           File
>         "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
>         1537, in HandlerDispatch
>             default=default_handler, arg=req, silent=hlist.silent)
>         
>           File
>         "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
>         1229, in _process_target
>             result = _execute_target(config, req, object, arg)
>         
>           File
>         "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
>         1128, in _execute_target
>             result = object(arg)
>         
>           File "/var/www/apache2-default/test_python/mptest.py", line
>         13, in handler
>             r("library()")
>         
>           File
>         "/usr/lib/python2.5/site-packages/rpy2/robjects/__init__.py",
>         line 501, in __call__
>             res = self.eval(p)
>         
>           File
>         "/usr/lib/python2.5/site-packages/rpy2/robjects/__init__.py",
>         line 381, in __call__
>             res = super(RFunction, self).__call__(*new_args,
>         **new_kwargs)
>         
>         RRuntimeError: Error in gzfile(file, "rb") : invalid 'encoding'
>         argument
>         
> Any ideas?
> 
> --eric
> 
> 
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> rpy-list mailing list
> rpy-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rpy-list


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to