Skip to content

Commit 3d31af5

Browse files
FHaasePingviinituutti
authored andcommitted
DOC: Change code-block to ipython in r_interface.rst (pandas-dev#23906)
1 parent 69e2f1d commit 3d31af5

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

doc/source/r_interface.rst

+24-14
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,27 @@ See also the documentation of the `rpy2 <http://rpy2.bitbucket.org/>`__ project:
3333

3434
In the remainder of this page, a few examples of explicit conversion is given. The pandas conversion of rpy2 needs first to be activated:
3535

36-
.. code-block:: python
36+
.. ipython::
37+
:verbatim:
3738

38-
>>> from rpy2.robjects import pandas2ri # doctest: +SKIP
39-
>>> pandas2ri.activate() # doctest: +SKIP
39+
In [1]: from rpy2.robjects import pandas2ri
40+
...: pandas2ri.activate()
4041

4142
Transferring R data sets into Python
4243
------------------------------------
4344

4445
Once the pandas conversion is activated (``pandas2ri.activate()``), many conversions
4546
of R to pandas objects will be done automatically. For example, to obtain the 'iris' dataset as a pandas DataFrame:
4647

47-
.. code-block:: python
48+
.. ipython::
49+
:verbatim:
4850

49-
>>> from rpy2.robjects import r # doctest: +SKIP
50-
>>> r.data('iris') # doctest: +SKIP
51-
>>> r['iris'].head() # doctest: +SKIP
51+
In [2]: from rpy2.robjects import r
52+
53+
In [3]: r.data('iris')
54+
55+
In [4]: r['iris'].head()
56+
Out[4]:
5257
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5358
0 5.1 3.5 1.4 0.2 setosa
5459
1 4.9 3.0 1.4 0.2 setosa
@@ -66,14 +71,19 @@ Converting DataFrames into R objects
6671
The ``pandas2ri.py2ri`` function support the reverse operation to convert
6772
DataFrames into the equivalent R object (that is, **data.frame**):
6873

69-
.. code-block:: python
74+
.. ipython::
75+
:verbatim:
76+
77+
In [5]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]},
78+
...: index=["one", "two", "three"])
79+
80+
In [6]: r_dataframe = pandas2ri.py2ri(df)
81+
82+
In [7]: print(type(r_dataframe))
83+
Out[7]: <class 'rpy2.robjects.vectors.DataFrame'>
7084

71-
>>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]},
72-
... index=["one", "two", "three"]) # doctest: +SKIP
73-
>>> r_dataframe = pandas2ri.py2ri(df) # doctest: +SKIP
74-
>>> print(type(r_dataframe)) # doctest: +SKIP
75-
<class 'rpy2.robjects.vectors.DataFrame'>
76-
>>> print(r_dataframe) # doctest: +SKIP
85+
In [8]: print(r_dataframe)
86+
Out[8]:
7787
A B C
7888
one 1 4 7
7989
two 2 5 8

0 commit comments

Comments
 (0)