How to suppress error messages in rpy2

Posted by Björn on Stack Overflow See other posts from Stack Overflow or by Björn
Published on 2010-04-23T16:00:40Z Indexed on 2010/04/23 16:03 UTC
Read the original article Hit count: 243

Filed under:
|
|

Hello! The following code does not work. It seems that the R warning message raises a python error.

# enable use of python objects in rpy2
import rpy2.robjects.numpy2ri
import numpy as np
from rpy2.robjects import r

# create an example array
a = np.array([[5,2,5],[3,7,8]])

# this line leads to a warning message, which in turn raises an 
# error message if run within a script.
result = r['chisq.test'](a)

Running that code example in ipython works, however, running it inside a script raises the errorTypeError: 'module' object is unsubscriptable. I assume this is due to the warning message.

What is the best way to avoid this problem? Thanks in advance!

© Stack Overflow or respective owner

Related posts about rpy2

Related posts about python