You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/source/r_interface.rst
+63-1
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,69 @@ rpy2 / R interface
15
15
16
16
.. warning::
17
17
18
-
In v0.16.0, the ``pandas.rpy`` interface has been **deprecated and will be removed in a future version**. Similar functionaility can be accessed thru the `rpy2 <http://rpy.sourceforge.net/>`_ project.
18
+
In v0.16.0, the ``pandas.rpy`` interface has been **deprecated and will be
19
+
removed in a future version**. Similar functionality can be accessed
20
+
through the `rpy2 <http://rpy.sourceforge.net/>`_ project.
21
+
See the :ref:`updating <rpy.updating>` section for a guide to port your
22
+
code from the ``pandas.rpy`` to ``rpy2`` functions.
23
+
24
+
25
+
.. _rpy.updating:
26
+
27
+
Updating your code to use rpy2 functions
28
+
----------------------------------------
29
+
30
+
In v0.16.0, the ``pandas.rpy`` module has been **deprecated** and users are
31
+
pointed to the similar functionality in ``rpy2`` itself (rpy2 >= 2.4).
32
+
33
+
Instead of importing ``import pandas.rpy.common as com``, the following imports
34
+
should be done to activate the pandas conversion support in rpy2::
35
+
36
+
from rpy2.robjects import pandas2ri
37
+
pandas2ri.activate()
38
+
39
+
Converting data frames back and forth between rpy2 and pandas should be largely
40
+
automated (no need to convert explicitly, it will be done on the fly in most
41
+
rpy2 functions).
42
+
43
+
To convert explicitly, the functions are ``pandas2ri.py2ri()`` and
44
+
``pandas2ri.ri2py()``. So these functions can be used to replace the existing
45
+
functions in pandas:
46
+
47
+
- ``com.convert_to_r_dataframe(df)`` should be replaced with ``pandas2ri.py2ri(df)``
48
+
- ``com.convert_robj(rdf)`` should be replaced with ``pandas2ri.ri2py(rdf)``
49
+
50
+
Note: these functions are for the latest version (rpy2 2.5.x) and were called
51
+
``pandas2ri.pandas2ri()`` and ``pandas2ri.ri2pandas()`` previously.
52
+
53
+
Some of the other functionality in `pandas.rpy` can be replaced easily as well.
54
+
For example to load R data as done with the ``load_data`` function, the
55
+
current method::
56
+
57
+
df_iris = com.load_data('iris')
58
+
59
+
can be replaced with::
60
+
61
+
from rpy2.robjects import r
62
+
r.data('iris')
63
+
df_iris = pandas2ri.ri2py(r[name])
64
+
65
+
The ``convert_to_r_matrix`` function can be replaced by the normal
66
+
``pandas2ri.py2ri`` to convert dataframes, with a subsequent call to R
67
+
``as.matrix`` function.
68
+
69
+
.. warning::
70
+
71
+
Not all conversion functions in rpy2 are working exactly the same as the
72
+
current methods in pandas. If you experience problems or limitations in
73
+
comparison to the ones in pandas, please report this at the
0 commit comments