Skip to main content

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.

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, or predict() 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 like ggplot2
  • 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 (R packages are auto-installed as needed)

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

rpynative-0.1.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rpynative-0.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file rpynative-0.1.0.tar.gz.

File metadata

  • Download URL: rpynative-0.1.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for rpynative-0.1.0.tar.gz
Algorithm Hash digest
SHA256 728a8cf548c7f9f1e46b9412524af21738bcf4f67b34af1ced7d7bc4f08efa3a
MD5 758f3445cf4fac769b79f9a1c77ff783
BLAKE2b-256 6c2ed3294008ba9ed9ee743b6d9770625d3ff7a24eee5fd7a0053253676941fb

See more details on using hashes here.

File details

Details for the file rpynative-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rpynative-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for rpynative-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf74aa73c646cc3417ca9bb76a2782c64418993296de6cd9ce0faaf02f5ddd5b
MD5 5df78e995f9c09102e32752f159b3f84
BLAKE2b-256 3738ded777df0c2af4a1efcb128c04cce5bda1028b5b8e473153b52b3dd28d63

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page