Rpy2 Tutorial: How to Run R in Python
In this post, we are going to answer the question can you run R in Python? Of course, the answer is yes!; using the Python package rpy2. This package offers a Python interface to R.
In this tutorial, we will learn how to use rpy2 to install r packages and run r functions to carry out data analysis and data visualization. More specifically, we will learn how to sue the r packages r-packages ‘afex‘ and ‘emmeans‘, using Python, and rpy2. Finally, we will also learn how to display R plots in Jupyter notebooks using rpy2, using two different methods.
Obviously; rpy2 requires that we have both R (version +3.2.x) and Python (versions 2.7 and 3.X) installed. There are pre-compiled binaries available for Linux and Windows (unsupported and unofficial, however).