rpynative
Use R packages natively in Python, no R knowledge required.
rpynative lets Python developers load and use R packages as if they were normal Python packages. No R syntax, no manual object conversion, and unlike other R-Python bridges, rpynative even supports real IDE autocomplete for R functions.
⚠️ Requires R to be installed on your system.
rpynativeis not a pure-Python package, it's built on rpy2, meaning the real chain is:
Python → rpynative → rpy2 → R
pip install rpynativewill succeed even without R installed, but using it will fail until R is available on your system. See Requirements below before you start.
Why not just use rpy2?
rpynative is built on top of rpy2, rpy2 is the engine, rpynative is what a Python-only developer actually experiences using it. rpy2 exposes R concepts directly (R vectors, manual converter contexts, raw R objects), it's a bridge for people who already know R. rpynative is built for people who don't, and want R's tools to feel like native Python.
Specifically, rpynative adds:
- Zero R knowledge required : pass plain Python lists/DataFrames, get back plain Python dicts/DataFrames
- Auto-install : missing R packages are installed from CRAN automatically
- Preserved native reporting : R's own nicely-formatted print output (e.g. a package's custom statistical report) is captured and shown, not just raw data
- Object-chaining and generic dispatch handled transparently: things like
ggplot2's+syntax, orpredict()working across any model type, just work - Auto-generated IDE stubs: real autocomplete and parameter hints in editors like VS Code for a dynamically loaded R package's functions
- Round-tripping of complex objects: trained models, plots, and other R objects can be passed back into other R functions without losing their identity
Example
import rpynative
stats = rpynative.load("stats")
result = stats.mean([2, 4, 6, 8, 10])
print(result) # 6.0
Real statistical reports, not raw R objects
statease = rpynative.load("statease")
result = statease.ttest_interpret([88, 92, 79, 85, 90], [70, 65, 72, 68, 74])
print(result)
# -- statease T-Test Report ----------------------------------------
# Test : Independent Samples T-Test
# ...
print(result['p_val']) # still works like a normal dict
Formulas, DataFrames, matrices, and S4 objects
import pandas as pd
data = pd.DataFrame({"score": [...], "group": [...]})
result = statease.anova_interpret("score ~ group", data=data)
print(result)
Visual/plotting packages
ggplot2 = rpynative.load("ggplot2")
plot = ggplot2.ggplot(data, ggplot2.aes(x="x", y="y")) + ggplot2.geom_point()
ggplot2.ggsave("plot.png", plot=plot)
Real machine learning workflows
randomForest = rpynative.load("randomForest")
model = randomForest.randomForest("outcome ~ feature1 + feature2", data=data)
predictions = randomForest.predict(model, new_data)
IDE autocomplete for R functions
from rpynative.core import load_typed
from rpynative.stubs.statease import StateaseStub
statease = load_typed("statease", StateaseStub)
statease. # <- VS Code shows real autocomplete here
Note: autocomplete currently requires generating a stub once per package (rpynative.stub_generator.generate_stub("packagename")). Automatic stub generation on load() is a planned improvement.
Features
- Load any R package with one line, auto-installs it from CRAN if missing
- Automatic conversion: lists, numbers, pandas DataFrames, R formulas, matrices (as numpy arrays), S4 objects (as dicts)
- Rich report output preserved alongside clean programmatic access
- Object-chaining support (
+operator) for packages likeggplot2 - Generic function dispatch (
predict,summary, etc.) works across any model type - Built-in R datasets accessible directly as pandas DataFrames
- Auto-generated IDE stubs for real autocomplete
- Clean Python errors instead of raw R tracebacks
Requirements
- Python 3.9+
- R installed and available on your system, download from r-project.org if you don't have it
- R must be discoverable on your system PATH (on Windows, this sometimes requires adding R's
binfolder to PATH manually after installing R, see R's Windows FAQ ifR --versiondoesn't work in your terminal)
Individual R packages (like stats, ggplot2, etc.) do not need to be pre-installed, rpynative installs them automatically from CRAN the first time you load them.
Installation
pip install rpynative
Then verify your R installation is discoverable:
python -c "import rpynative; v = rpynative.load('base').getRversion(); print('R version:', '.'.join(str(x) for x in v))"
If this raises an error instead of printing an R version string, rpynative is installed correctly, but R itself isn't discoverable yet, check the PATH note above.
Installation
pip install rpynative
Known limitations
- IDE autocomplete requires a manual one-time stub generation step per package
- Not yet tested against every R object type across all ~20,000 CRAN packages, common types (S3, S4, matrices, data.frames, formulas) are covered and tested; more exotic types may surface new edge cases
- Windows, macOS, and Linux should all work (R + rpy2 support all three), but development and testing so far has been primarily on Windows
Status
Actively developed. Core engine, report handling, plotting support, matrix/S4 support, and IDE autocomplete are all working and tested against real published R packages, including real machine learning workflows.
Author
Built by DevWebWacky, also the author of the statease R package used throughout development and testing, and triageR
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rpynative-0.1.2.tar.gz.
File metadata
- Download URL: rpynative-0.1.2.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d66b184322d783e1fffaf568355f7a858627121dd56bbcbf6da6fa88929ec426
|
|
| MD5 |
ad1388d2ace762c2d53758002958e813
|
|
| BLAKE2b-256 |
d86fd1e1ce739450e46a63aea9cb92c7f4a954adcfac7e9888ac8cbace7cd5cb
|
File details
Details for the file rpynative-0.1.2-py3-none-any.whl.
File metadata
- Download URL: rpynative-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8886936908c07cfa0ac46dfdd0a6dfa96a1a467c4c439425fc5150580ba74c21
|
|
| MD5 |
4f116a8c403bbe4bbf5d875c2e6e6589
|
|
| BLAKE2b-256 |
13cae75915d7acb70b34944ad7b5dbd6799e3ff713b3b9a9e7976c9b2e58b31c
|