As pointed out by Ian, the problem is partly originating from the conversion from pandas' DataFrames to rpy2/R's Dataframes (the other part of the problem is originiting from np's npreg()
(other modeling function do work fine, as you noted it).
There is work toward improving that in rpy2-2.4.0, so make sure you report issues (and possibly try a recent snapshot of rpy2-2.4.0-dev).
A more immediate (and simple) solution can be obtained as follows (tested with rpy2-2.3.9 and 2.4.0-dev, and with pandas 0.13.0 / R-3.0.2-patched):
# Your pandas DataFrame
py_df = pd.DataFrame(np.random.randn(100,3), columns=['y', 'x_1', 'x_2'])
r_df = com.convert_to_r_dataframe(py_df)
The type is AsIs
. A possible simpler way to see it is:
>>> [tuple(x.rclass) for x in r_df]
[('AsIs',), ('AsIs',), ('AsIs',)]
Now we just want to drop the class AsIs
:
for col in r_df:
col.rclass = None
The vectors are back to their basic type:
>>> [tuple(x.rclass) for x in r_df]
[('numeric',), ('numeric',), ('numeric',)]
Now the call is running without error:
r_np.npreg(ro.Formula('y ~ x_1 + x_2'), data=r_df)