From 62c6c68ba65f1f1b018641b03948e0510b0987f0 Mon Sep 17 00:00:00 2001 From: Fabian Haase Date: Sun, 25 Nov 2018 15:50:19 +0100 Subject: [PATCH 1/3] Change code-block to ipython in r_interface.rst The documentation mainly uses the `.. ipython::` directive. This changes the code-blocks to ipython blocks so there is a unified visual style. Signed-off-by: Fabian Haase --- doc/source/r_interface.rst | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/doc/source/r_interface.rst b/doc/source/r_interface.rst index d0b2601668069..f40f9199aaf66 100644 --- a/doc/source/r_interface.rst +++ b/doc/source/r_interface.rst @@ -33,10 +33,11 @@ See also the documentation of the `rpy2 `__ project: In the remainder of this page, a few examples of explicit conversion is given. The pandas conversion of rpy2 needs first to be activated: -.. code-block:: python +.. ipython:: + :verbatim: - >>> from rpy2.robjects import pandas2ri # doctest: +SKIP - >>> pandas2ri.activate() # doctest: +SKIP + In [1]: from rpy2.robjects import pandas2ri + ...: pandas2ri.activate() Transferring R data sets into Python ------------------------------------ @@ -44,11 +45,15 @@ Transferring R data sets into Python Once the pandas conversion is activated (``pandas2ri.activate()``), many conversions of R to pandas objects will be done automatically. For example, to obtain the 'iris' dataset as a pandas DataFrame: -.. code-block:: python +.. ipython:: + :verbatim: - >>> from rpy2.robjects import r # doctest: +SKIP - >>> r.data('iris') # doctest: +SKIP - >>> r['iris'].head() # doctest: +SKIP + In [2]: from rpy2.robjects import r + + In [3]: r.data('iris') + + In [4]: r['iris'].head() + Out[4]: Sepal.Length Sepal.Width Petal.Length Petal.Width Species 0 5.1 3.5 1.4 0.2 setosa 1 4.9 3.0 1.4 0.2 setosa @@ -66,14 +71,19 @@ Converting DataFrames into R objects The ``pandas2ri.py2ri`` function support the reverse operation to convert DataFrames into the equivalent R object (that is, **data.frame**): -.. code-block:: python +.. ipython:: + :verbatim: + + In [5]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}, + ...: index=["one", "two", "three"]) + + In [6]: r_dataframe = pandas2ri.py2ri(df) + + In [7]: print(type(r_dataframe)) + Out[7]: - >>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}, - ... index=["one", "two", "three"]) # doctest: +SKIP - >>> r_dataframe = pandas2ri.py2ri(df) # doctest: +SKIP - >>> print(type(r_dataframe)) # doctest: +SKIP - - >>> print(r_dataframe) # doctest: +SKIP + In [8]: print(r_dataframe) + Out[8]: A B C one 1 4 7 two 2 5 8 From e0613b71e7edf58a69b2bfda2a254264390caac2 Mon Sep 17 00:00:00 2001 From: Fabian Haase Date: Mon, 26 Nov 2018 01:33:16 +0100 Subject: [PATCH 2/3] Review of @datapythonista Signed-off-by: Fabian Haase --- doc/source/r_interface.rst | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/doc/source/r_interface.rst b/doc/source/r_interface.rst index f40f9199aaf66..8db0bab182599 100644 --- a/doc/source/r_interface.rst +++ b/doc/source/r_interface.rst @@ -33,11 +33,11 @@ See also the documentation of the `rpy2 `__ project: In the remainder of this page, a few examples of explicit conversion is given. The pandas conversion of rpy2 needs first to be activated: -.. ipython:: +.. ipython:: python :verbatim: - In [1]: from rpy2.robjects import pandas2ri - ...: pandas2ri.activate() + >>> from rpy2.robjects import pandas2ri + >>> pandas2ri.activate() Transferring R data sets into Python ------------------------------------ @@ -45,15 +45,12 @@ Transferring R data sets into Python Once the pandas conversion is activated (``pandas2ri.activate()``), many conversions of R to pandas objects will be done automatically. For example, to obtain the 'iris' dataset as a pandas DataFrame: -.. ipython:: +.. ipython:: python :verbatim: - In [2]: from rpy2.robjects import r - - In [3]: r.data('iris') - - In [4]: r['iris'].head() - Out[4]: + >>> from rpy2.robjects import r + >>> r.data('iris') + >>> r['iris'].head() Sepal.Length Sepal.Width Petal.Length Petal.Width Species 0 5.1 3.5 1.4 0.2 setosa 1 4.9 3.0 1.4 0.2 setosa @@ -71,19 +68,15 @@ Converting DataFrames into R objects The ``pandas2ri.py2ri`` function support the reverse operation to convert DataFrames into the equivalent R object (that is, **data.frame**): -.. ipython:: +.. ipython:: python :verbatim: - In [5]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}, - ...: index=["one", "two", "three"]) - - In [6]: r_dataframe = pandas2ri.py2ri(df) - - In [7]: print(type(r_dataframe)) - Out[7]: - - In [8]: print(r_dataframe) - Out[8]: + >>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}, + ... index=["one", "two", "three"]) + >>> r_dataframe = pandas2ri.py2ri(df) + >>> print(type(r_dataframe)) + + >>> print(r_dataframe) A B C one 1 4 7 two 2 5 8 From 9a2d98f7cf49b06326e1a218cd496b0a964aa94e Mon Sep 17 00:00:00 2001 From: Fabian Haase Date: Mon, 26 Nov 2018 01:37:05 +0100 Subject: [PATCH 3/3] Revert "Review of @datapythonista" This reverts commit e0613b71 Signed-off-by: Fabian Haase --- doc/source/r_interface.rst | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/doc/source/r_interface.rst b/doc/source/r_interface.rst index 8db0bab182599..f40f9199aaf66 100644 --- a/doc/source/r_interface.rst +++ b/doc/source/r_interface.rst @@ -33,11 +33,11 @@ See also the documentation of the `rpy2 `__ project: In the remainder of this page, a few examples of explicit conversion is given. The pandas conversion of rpy2 needs first to be activated: -.. ipython:: python +.. ipython:: :verbatim: - >>> from rpy2.robjects import pandas2ri - >>> pandas2ri.activate() + In [1]: from rpy2.robjects import pandas2ri + ...: pandas2ri.activate() Transferring R data sets into Python ------------------------------------ @@ -45,12 +45,15 @@ Transferring R data sets into Python Once the pandas conversion is activated (``pandas2ri.activate()``), many conversions of R to pandas objects will be done automatically. For example, to obtain the 'iris' dataset as a pandas DataFrame: -.. ipython:: python +.. ipython:: :verbatim: - >>> from rpy2.robjects import r - >>> r.data('iris') - >>> r['iris'].head() + In [2]: from rpy2.robjects import r + + In [3]: r.data('iris') + + In [4]: r['iris'].head() + Out[4]: Sepal.Length Sepal.Width Petal.Length Petal.Width Species 0 5.1 3.5 1.4 0.2 setosa 1 4.9 3.0 1.4 0.2 setosa @@ -68,15 +71,19 @@ Converting DataFrames into R objects The ``pandas2ri.py2ri`` function support the reverse operation to convert DataFrames into the equivalent R object (that is, **data.frame**): -.. ipython:: python +.. ipython:: :verbatim: - >>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}, - ... index=["one", "two", "three"]) - >>> r_dataframe = pandas2ri.py2ri(df) - >>> print(type(r_dataframe)) - - >>> print(r_dataframe) + In [5]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}, + ...: index=["one", "two", "three"]) + + In [6]: r_dataframe = pandas2ri.py2ri(df) + + In [7]: print(type(r_dataframe)) + Out[7]: + + In [8]: print(r_dataframe) + Out[8]: A B C one 1 4 7 two 2 5 8