When calling
r('lmout <- lm(r_df$a ~ r_df$b)')
the embedded R will look for a variable r_df
, and no such variable is made visible to R in your code example.
When doing
r_df = com.convert_to_r_dataframe(datframe)
you are creating the variable r_df
on the Python side but while the actual data in now in R, there is no symbol (name) associated with it known to R. That data structure remains anonymous.
(btw, you may want to use the automagic conversion of pandas data frames shipping with rpy2-2.3.3).
To create a variable name in R's "global environment", add this:
from rpy2.robjects import globalenv
globalenv['r_df'] = r_df
Now your lm()
call should work.