Registry / data / rpy2
library3.6.7pypypiunverified

rpy2 is an active Python library (version 3.6.7 as of March 27, 2026) that provides a robust interface to the R programming language, allowing Python programs to seamlessly integrate and leverage R's extensive statistical and graphical capabilities. It supports embedded R execution, data conversion between Python (e.g., Pandas, NumPy) and R objects, and direct calling of R functions and packages. The `robjects` subpackage provides a high-level, Pythonic interface to R objects and functions.

pip install rpy2
INSTALL
IMPORT
SIG · RPY2
R
rpy2
datapythonv3.6.7
Install
—
Import
—
Disk
—
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
build_error
glibc
py 3.10–3.920 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

robjects
✓ import rpy2.robjects as robjects
The primary high-level interface to R objects.
importr
✓ from rpy2.robjects.packages import importr
Function to import R packages as Python modules.
pandas2ri
✓ from rpy2.robjects import pandas2ri
Module for converting Pandas DataFrames to R data.frames and vice-versa. Requires activation.

This quickstart demonstrates how to initialize rpy2, run arbitrary R code, convert data between Python (Pandas) and R, and call R functions directly using the `robjects` interface. It includes activating `pandas2ri` for seamless DataFrame conversion.

import rpy2.robjects as ro from rpy2.robjects.packages import importr from rpy2.robjects import pandas2ri import pandas as pd # Activate pandas to R conversion pandas2ri.activate() # Import R's 'base' package and 'stats' package base = importr('base') stats = importr('stats') # Run arbitrary R code r_code = "x <- c(1, 2, 3, 4, 5); mean(x)" r_result = ro.r(r_code) print(f"R mean result: {r_result[0]}") # Create a Pandas DataFrame and convert to R py_df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}) r_df = pandas2ri.py2rpy(py_df) print(f"R DataFrame content:\n{r_df}") # Call an R function directly r_sum = base.sum(ro.IntVector([10, 20, 30])) print(f"R sum result: {r_sum[0]}")
Debug
Known issues
breakingPython 3.8 support was dropped in rpy2 v3.6.5. rpy2 now requires Python >= 3.9.
fix
Upgrade your Python environment to 3.9 or higher. If unable, pin rpy2 to <3.6.5.
affects: 3.6.5+
breakingR-4.6.0 hides certain C functions previously used by rpy2. To ensure compatibility, rpy2 version 3.6.7 or newer is required when using R-4.6.0.
fix
Update rpy2 to version 3.6.7 or later: `pip install --upgrade rpy2`.
affects: rpy2 <3.6.7 with R >=4.6.0
gotchaOn Windows, rpy2's API mode for CFFI is only 'ABI' by default, leading to warnings or failures if 'API' or 'BOTH' is implicitly or explicitly requested without proper setup. The `RPY2_CFFI_MODE` environment variable may need to be set.
fix
To force ABI mode and suppress warnings, set the environment variable `RPY2_CFFI_MODE=ABI` before importing rpy2. For API mode, set `RPY2_CFFI_MODE=API` and ensure R is correctly in PATH or R_HOME is defined.
affects: 3.6.5+ (Windows)
gotchaThe methods `rpy2.robjects.environment.Environment.enclos` and `rpy2.rinterface_lib.sexp.CharSxp.nchar()` are deprecated and will raise a `RuntimeError` if used.
fix
Avoid using these deprecated methods. Consult the rpy2 documentation for alternative approaches to achieve similar functionality.
affects: 3.6.x+
Upgrade
Version history
3.6.7latest on PyPI · released Mar 27, 2026
Audit
Dependencies
pythonrequiredRequired Python version.
Rrequiredrpy2 embeds R; an R installation is required on the system.
packagingrequiredCore dependency for package metadata handling.
rpy2-rinterfacerequiredLow-level R interface, part of the rpy2 namespace package.
rpy2-robjectsrequiredHigh-level R objects interface, part of the rpy2 namespace package.
numpyoptionalFor seamless conversion between NumPy arrays and R vectors/matrices.
pandasoptionalFor seamless conversion between Pandas DataFrames and R data.frames.
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
rpy2 — pip install rpy2 · libregistry