{"id":6863,"library":"rpy2","title":"rpy2 (robjects) - Python to R Interface","description":"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.","status":"active","version":"3.6.7","language":"python","source_language":"en","source_url":"https://github.com/rpy2/rpy2","tags":["R","data science","interoperability","statistical computing","embedded R"],"install":[{"cmd":"pip install rpy2","lang":"bash","label":"Install latest stable version"}],"dependencies":[{"reason":"Required Python version.","package":"python","version":">=3.9","optional":false},{"reason":"rpy2 embeds R; an R installation is required on the system.","package":"R","version":">=3.6.0","optional":false},{"reason":"Core dependency for package metadata handling.","package":"packaging","optional":false},{"reason":"Low-level R interface, part of the rpy2 namespace package.","package":"rpy2-rinterface","optional":false},{"reason":"High-level R objects interface, part of the rpy2 namespace package.","package":"rpy2-robjects","optional":false},{"reason":"For seamless conversion between NumPy arrays and R vectors/matrices.","package":"numpy","optional":true},{"reason":"For seamless conversion between Pandas DataFrames and R data.frames.","package":"pandas","optional":true}],"imports":[{"note":"The primary high-level interface to R objects.","symbol":"robjects","correct":"import rpy2.robjects as robjects"},{"note":"Function to import R packages as Python modules.","symbol":"importr","correct":"from rpy2.robjects.packages import importr"},{"note":"Module for converting Pandas DataFrames to R data.frames and vice-versa. Requires activation.","symbol":"pandas2ri","correct":"from rpy2.robjects import pandas2ri"}],"quickstart":{"code":"import rpy2.robjects as ro\nfrom rpy2.robjects.packages import importr\nfrom rpy2.robjects import pandas2ri\nimport pandas as pd\n\n# Activate pandas to R conversion\npandas2ri.activate()\n\n# Import R's 'base' package and 'stats' package\nbase = importr('base')\nstats = importr('stats')\n\n# Run arbitrary R code\nr_code = \"x <- c(1, 2, 3, 4, 5); mean(x)\"\nr_result = ro.r(r_code)\nprint(f\"R mean result: {r_result[0]}\")\n\n# Create a Pandas DataFrame and convert to R\npy_df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})\nr_df = pandas2ri.py2rpy(py_df)\nprint(f\"R DataFrame content:\\n{r_df}\")\n\n# Call an R function directly\nr_sum = base.sum(ro.IntVector([10, 20, 30]))\nprint(f\"R sum result: {r_sum[0]}\")","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or higher. If unable, pin rpy2 to <3.6.5.","message":"Python 3.8 support was dropped in rpy2 v3.6.5. rpy2 now requires Python >= 3.9.","severity":"breaking","affected_versions":"3.6.5+"},{"fix":"Update rpy2 to version 3.6.7 or later: `pip install --upgrade rpy2`.","message":"R-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.","severity":"breaking","affected_versions":"rpy2 <3.6.7 with R >=4.6.0"},{"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.","message":"On 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.","severity":"gotcha","affected_versions":"3.6.5+ (Windows)"},{"fix":"Avoid using these deprecated methods. Consult the rpy2 documentation for alternative approaches to achieve similar functionality.","message":"The methods `rpy2.robjects.environment.Environment.enclos` and `rpy2.rinterface_lib.sexp.CharSxp.nchar()` are deprecated and will raise a `RuntimeError` if used.","severity":"gotcha","affected_versions":"3.6.x+"}],"env_vars":null,"search_vec":"'2026':19 '27':18 '3.6.7':14 'activ':10 'allow':30 'call':62 'capabl':44 'comput':88 'convers':51 'data':50,84 'direct':61 'e.g':54 'embed':47,89 'execut':49 'extens':40 'function':65,82 'graphic':43 'high':74 'high-level':73 'integr':35 'interfac':6,24,77 'interoper':86 'languag':29 'level':75 'leverag':37 'librari':12 'march':17 'numpi':56 'object':59,80 'packag':67 'panda':55 'program':28,32 'provid':21,71 'python':3,11,31,53,76 'r':5,27,38,48,58,64,79,83,90 'robject':2,69 'robust':23 'rpy2':1,7 'scienc':85 'seamless':34 'statist':41,87 'subpackag':70 'support':46 'version':13","created_at":"2026-04-15T18:46:15.609070+00:00","updated_at":"2026-04-16T17:03:03.632754+00:00","problems":{"verify_error":"× Failed to build `rpy2-rinterface==3.6.6`\n  ├─▶ The build backend returned an error\n  ╰─▶ Call to `setuptools.build_meta.build_wheel` failed (exit status: 1)\n\n      [stdout]\n      cffi mode is CFFI_MODE.ANY\n      Looking for R home with: R RHOME\n      R home found: None\n\n      [stderr]\n      Unable"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"3.6.7","cli_name":"","cli_version":null,"type":"library","homepage":"https://rpy2.github.io","github":"https://github.com/rpy2/rpy2","docs":"https://rpy2.github.io/doc.html","changelog":null,"pypi":"https://pypi.org/project/rpy2/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"install_fail","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-05","install_tag":null}}