Re: [Rpy] Using rpy2 with lib-apache2-mod-python
On Mon, 2008-10-20 at 21:12 -0700, Eric Bell wrote: Resolved ... or a least made to go away. It appears that the problem was caused in part due to loading another apache module supplied by R/Apache, as described at http://biostat.mc.vanderbilt.edu/rapache/ R/Apache is a project dedicated to embedding the R interpreter inside the Apache 2.0 (and beyond) web server I was looking through the apache error log, and noticed the lines: Error in .Call(R_isMethodsDispatchOn, onOff, PACKAGE = base) : Incorrect number of arguments (2), expecting 1 for R_isMethodsDispatchOn I don't know if the R/Apache r_module is causing this or rpy2, but I decided to disable the r_module and voila, my script works ... One possibility is that R gets initialized twice then (and R does not like that). I'll look into having rpy2 detect this kind of situation. well actually it doesn't, because now I get another error, but that's due to trying to use a call to JPEG, which requires that an X11 device be present, which it won't be running inside a web server. R's man page for jpeg() states it, and alternatives to use when no X11. --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=100url=/ ___ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list
Re: [Rpy] Using rpy2 with lib-apache2-mod-python
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=100url=/ ___ rpy-list
Re: [Rpy] Using rpy2 with lib-apache2-mod-python
On Mon, 2008-10-20 at 12:39 -0700, Eric Bell wrote: No change in behavior. I've simplifed my python script and added the import rpy2.rinterface as instructed. I've stopped and started the apache server as appropriate voodoo. No change was expected: '--verbose' instructs R to tell a bit more of what it is doing. Looking whether a hint appear when inspecting what it tells is the way to go (although I am not sure that a hint appears, as mentioned in a previous email). Seems to me if I can't execute the library() call then it makes sense that R functionality in the non-base libraries won't be available. Other info: I'm running on Unbuntu Gusty ... I couldn't find a packaged shared libraries version of R so I built it myself. I did have R installed previously using the Synaptic package manager and subsequently deinstalled when I built the shared library version. I've just confirmed that Synatpic indicates that R is not installed. I notice that if I do a printenv in a shell, there's no R_HOME variable defined. Should there be? I recall having to futz with this when I was trying to install the RSPython extension...the builds kept failing because R_HOME was point to the wrong place. I'm happy to run other tests if you tell me what to do. Running the unit tests (see the documentation for rpy2) in order to ensure that installation is otherwise proper is something recommended, if not already done. --eric PYTHON SCRIPT from mod_python import apache import rpy2.rinterface as ri # this must go before the import rpy2 ri.set_initoptions(('rpy2','--verbose','--vanilla','--nosave')) import rpy2 from rpy2 import robjects def handler(req): r = robjects.r r(library()) req.content_type = 'html' req.write(HTMLBODYHello beautiful World!BR/BODY/HTML) return apache.OK Traceback: 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/test1.py, line 14, 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 - 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=100url=/ ___ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list
Re: [Rpy] Using rpy2 with lib-apache2-mod-python
No change in behavior. I've simplifed my python script and added the import rpy2.rinterface as instructed. I've stopped and started the apache server as appropriate voodoo. Seems to me if I can't execute the library() call then it makes sense that R functionality in the non-base libraries won't be available. Other info: I'm running on Unbuntu Gusty ... I couldn't find a packaged shared libraries version of R so I built it myself. I did have R installed previously using the Synaptic package manager and subsequently deinstalled when I built the shared library version. I've just confirmed that Synatpic indicates that R is not installed. I notice that if I do a printenv in a shell, there's no R_HOME variable defined. Should there be? I recall having to futz with this when I was trying to install the RSPython extension...the builds kept failing because R_HOME was point to the wrong place. I'm happy to run other tests if you tell me what to do. --eric PYTHON SCRIPT from mod_python import apache import rpy2.rinterface as ri # this must go before the import rpy2 ri.set_initoptions(('rpy2','--verbose','--vanilla','--nosave')) import rpy2 from rpy2 import robjects def handler(req): r = robjects.r r(library()) req.content_type = 'html' req.write(HTMLBODYHello beautiful World!BR/BODY/HTML) return apache.OK Traceback: 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/test1.py, line 14, 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 - 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=100url=/___ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list
Re: [Rpy] Using rpy2 with lib-apache2-mod-python
I performed the unit testing and here are my results: Note: Software Versions: R 2.7.2 Python 2.5.1 $ python Python 2.5.1 (r251:54863, Jul 31 2008, 23:17:40) [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2 Type help, copyright, credits or license for more information. import rpy2.tests import unittest tr = unittest.TextTestRunner(verbosity = 1) suite = rpy2.tests.suite() tr.run(suite) ..Error in .Primitive([)(0:10, list(a, b, c)) : invalid subscript type 'list' E..FLoading required package: splines ..Error in function (x) : object y not found ...Error in .Primitive(sum)(c(a, b, c, d, e, f, g, h, i, : invalid 'type' (character) of argument ..F.. == ERROR: testNewString (rpy2.rinterface.tests.test_SexpVector.SexpVectorTestCase) -- Traceback (most recent call last): File /usr/lib/python2.5/site-packages/rpy2/rinterface/tests/test_SexpVector.py, line 95, in testNewString ri.NA_STRING[0] ValueError: Cannot handle type 9 == FAIL: testNewWithoutInit (rpy2.rinterface.tests.test_SexpVector.SexpVectorTestCase) -- Traceback (most recent call last): File /usr/lib/python2.5/site-packages/rpy2/rinterface/tests/test_SexpVector.py, line 37, in testNewWithoutInit self.assertTrue(False) # worked when tested, but calling endEmbeddedR causes trouble AssertionError == FAIL: testCallErrorWhenEndedR (rpy2.rinterface.tests.test_EmbeddedR.EmbeddedRTestCase) -- Traceback (most recent call last): File /usr/lib/python2.5/site-packages/rpy2/rinterface/tests/test_EmbeddedR.py, line 30, in testCallErrorWhenEndedR self.assertTrue(False) # worked when tested, but calling endEmbeddedR causes trouble AssertionError -- Ran 144 tests in 0.269s FAILED (failures=2, errors=1) unittest._TextTestResult run=144 errors=1 failures=2 - 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=100url=/___ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list
Re: [Rpy] Using rpy2 with lib-apache2-mod-python
Resolved ... or a least made to go away. It appears that the problem was caused in part due to loading another apache module supplied by R/Apache, as described at http://biostat.mc.vanderbilt.edu/rapache/ R/Apache is a project dedicated to embedding the R interpreter inside the Apache 2.0 (and beyond) web server I was looking through the apache error log, and noticed the lines: Error in .Call(R_isMethodsDispatchOn, onOff, PACKAGE = base) : Incorrect number of arguments (2), expecting 1 for R_isMethodsDispatchOn I don't know if the R/Apache r_module is causing this or rpy2, but I decided to disable the r_module and voila, my script works ... well actually it doesn't, because now I get another error, but that's due to trying to use a call to JPEG, which requires that an X11 device be present, which it won't be running inside a web server. --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=100url=/ ___ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list