The rpy2 package provides a way of using R components as python objects.
from rpy2.robjects import r, pandas2ri
pandas2ri.activate()
r.data('iris')
r['iris'].head(2)
We can also use cell magic to allow us to cross back and forth between python
and R
code cells.
%load_ext rpy2.ipython
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C':[7,8,9]})
df
%%R -i df -o rdf
library(ggplot2)
rdf='My R created variable'
ggplot(df) + geom_point(aes(x=A,y=B,size=C)) + ggtitle(rdf)