Data Science

reticulate – R Interface to Python

The reticulate package provides a comprehensive set of tools for interoperability between Python and R.

The package includes facilities for:

  • Calling Python from R in a variety of ways including R Markdown, sourcing Python scripts, importing Python modules, and using Python interactively within an R session.
  • Translation between R and Python objects (for example, between R and Pandas data frames, or between R matrices and NumPy arrays).
  • Flexible binding to different versions of Python including virtual environments and Conda environments.

reticulate embeds a Python session within your R session, enabling seamless, high-performance interoperability. If you are an R developer that uses Python for some of your work or a member of data science team that uses both languages, reticulate can dramatically streamline your workflow.

Features include:

  • Offers different ways to integrate Python code into R projects:
    • Python in R Markdown — A new Python language engine for R Markdown that supports bi-directional communication between R and Python (R chunks can access Python objects and vice-versa):
      • Run Python chunks in a single Python session embedded within your R session (shared variables/state between Python chunks).
      • Printing of Python output, including graphical output from matplotlib.
      • Access to objects created within Python chunks from R using the py object (e.g. py$x would access an x variable created within Python from R).
      • Access to objects created within R chunks from Python using the r object (e.g. r.x would access to x variable created within R from Python)
    • Importing Python modules — The import() function enables you to import any Python module and call it’s functions directly from R.
    • Sourcing Python scripts — The source_python() function enables you to source a Python script the same way you would source() an R script (Python functions and objects defined within the script become directly available to the R session).
    • Python REPL — The repl_python() function creates an interactive Python console within R. Objects you create within Python are available to your R session (and vice-versa).

Website: rstudio.github.io/reticulate
Support: GitHub Code Repository
Developer: jjallaire, Tomasz Kalinowski, Kevin Ushey, and other contributors
License: Apache License 2.0

reticulate is written in R. Learn R with our recommended free books and free tutorials.


Related Software

Access Python from R
reticulateR Interface to Python
basiliskSmooth interoperability of multiple Python environments in a single R session
rpymatCreates and manages an isolated Miniconda and Python environment

Read our verdict in the software roundup.


Best Free and Open Source Software Explore our carefully curated directory of recommended free and open source software, covering every major software category.

The directory forms part of our extensive collection of articles for Linux enthusiasts. It includes hundreds of detailed reviews, together with free and open source alternatives to proprietary software from companies such as Google, Microsoft, Apple, Adobe, IBM, Cisco, Oracle, and Autodesk.

LinuxLinks also covers interesting projects worth exploring, Linux-compatible hardware, free programming books and tutorials, and much more.

Know a useful free and open source Linux application that we haven’t covered? Tell us about it using our submission form.
Subscribe

Please read our Comment Policy before commenting.

Notify of
guest
0 Comments
Oldest
Newest Most Voted