How-To: Rstudio: Use Reticulate Package to Manage R-Python Integration

Question

How do I use the reticulate package to manage R-Python integration?

 

Answer

1. Create and activate a new conda environment.

Note:  To create a conda environment for using Rstudio, see "How-To: Rstudio: Create Conda Environment for Using Rstudio"

 

2. Install reticulate (r-reticulate) package in the conda environment.

 

3. Set path and launch Rstudio

 

4. Create new R project

Note:  To create a new project in Rstudio, see " How-To: RStudio: Create a New Project with Renv "

 

5. Load reticulate package 

R prompt with "library(reticulate)"

 

6. Install python libraries using py_require()

Example: py_require("pandas") 

R prompt with py_require("pandas")

 

7. Import & use modules

Example: pandas <- import("pandas")

R prompt with pandas <- import("pandas")