rpy-bridge 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,258 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: rpy-bridge
3
- Version: 0.4.0
4
- Summary: Python-to-R interoperability engine with environment management, type-safe conversions, data normalization, and safe R function execution.
5
- Author-email: Victoria Cheung <victoriakcheung@gmail.com>
6
- License: MIT License
7
-
8
- Copyright (c) 2025 Victoria Cheung
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy
11
- of this software and associated documentation files (the "Software"), to deal
12
- in the Software without restriction, including without limitation the rights
13
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
- copies of the Software, and to permit persons to whom the Software is
15
- furnished to do so, subject to the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be included in all
18
- copies or substantial portions of the Software.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
- SOFTWARE.
27
-
28
- Acknowledgement: This project builds on work originally developed at
29
- Revolution Medicines and interfaces with the rpy2 project, which is licensed
30
- under the GNU General Public License version 2 or later.
31
-
32
- Project-URL: Homepage, https://github.com/vic-cheung/rpy-bridge
33
- Project-URL: Issue Tracker, https://github.com/vic-cheung/rpy-bridge/issues
34
- Keywords: python,r,rpy2,python-r,interoperability,data-science,statistics,bioinformatics
35
- Classifier: License :: OSI Approved :: MIT License
36
- Classifier: Programming Language :: Python
37
- Classifier: Programming Language :: Python :: 3
38
- Classifier: Programming Language :: Python :: 3.11
39
- Classifier: Programming Language :: Python :: 3.12
40
- Classifier: Intended Audience :: Developers
41
- Classifier: Intended Audience :: Science/Research
42
- Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
43
- Classifier: Topic :: Scientific/Engineering :: Information Analysis
44
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
45
- Requires-Python: >=3.11
46
- Description-Content-Type: text/markdown
47
- License-File: LICENSE
48
- Requires-Dist: numpy>=1.24
49
- Requires-Dist: pandas>=2.0
50
- Requires-Dist: loguru>=0.7
51
- Provides-Extra: r
52
- Requires-Dist: rpy2>=3.5; extra == "r"
53
- Provides-Extra: dev
54
- Requires-Dist: ipykernel>=7.1.0; extra == "dev"
55
- Provides-Extra: docs
56
- Requires-Dist: sphinx; extra == "docs"
57
- Requires-Dist: myst-parser; extra == "docs"
58
- Dynamic: license-file
59
-
60
- # rpy-bridge
61
-
62
- rpy-bridge is a Python-to-R a robust interoperability engine that combines environment management, type-safe conversions, data normalization, and safe function execution to make Python-R collaboration seamless.
63
-
64
- It enables Python developers to call R functions, scripts, and packages safely while preserving type fidelity and project-specific R environments. This is ideal for bilingual teams where R authors maintain core logic, and Python-centric users need reliable access without rewriting code.
65
-
66
- **Latest release:** [`rpy-bridge` on PyPI](https://pypi.org/project/rpy-bridge/)
67
-
68
- ---
69
-
70
- ## Key layers and capabilities
71
-
72
- ### 1. Lazy and robust R integration
73
-
74
- - Automatically detects or sets R_HOME and ensures rpy2 is installed.
75
- - Configures platform-specific dynamic library paths for macOS/Linux.
76
-
77
- ### 2. Environment management
78
-
79
- - Activates renv projects and loads project-specific libraries if it exists, otherwise use current environemnt.
80
- - Sources .Renviron and .Rprofile files to replicate the R project environment in Python.
81
-
82
- ### 3. Python ↔ R type conversion
83
-
84
- - Converts Python scalars, lists, dicts, and pandas DataFrames into appropriate R objects.
85
- - Converts R atomic vectors, ListVector/NamedList, and data.frames back into Python-native objects.
86
- - Handles nested structures, mixed types, and missing values robustly (NA_* → None/pd.NA).
87
-
88
- ### 4. Data hygiene and normalization
89
-
90
- - Post-processes R DataFrames: fixes dtypes, numeric/date conversions, and timezone issues.
91
- - Normalizes and aligns column types for accurate Python comparisons.
92
- - Supports comparing Python and R DataFrames with mismatch diagnostics.
93
-
94
- ### 5. Function calling
95
-
96
- - Calls functions from R scripts, base R, or installed packages safely.
97
- - Automatically converts arguments and return values, including keyword arguments.
98
- - Supports mixed data types, nested structures, and DataFrames seamlessly.
99
-
100
- ### 6. Python-first workflow for R code
101
-
102
- - Enables Python developers to reuse R functions without needing deep R knowledge.
103
- - Keeps network, token, and SSL concerns outside the package when sourcing scripts locally.
104
- - Designed for reproducibility and safe execution in CI or cross-platform environments.
105
-
106
- ---
107
-
108
- ## Installation
109
-
110
- **Prerequisites**
111
-
112
- - System R installed and available on `PATH` (rpy2 requires a working R installation).
113
- - Python 3.12+
114
-
115
- **From PyPI:**
116
-
117
- Install rpy-bridge with rpy2 for full R support
118
-
119
- ```bash
120
- python3 -m pip install rpy-bridge rpy2
121
- ```
122
-
123
- or using `uv`:
124
-
125
- ```bash
126
- uv add rpy-bridge rpy2
127
- ```
128
-
129
- **During development (editable install):**
130
-
131
- ```bash
132
- python3 -m pip install -e .
133
- ```
134
-
135
- or using `uv`:
136
-
137
- ```bash
138
- uv sync
139
- ```
140
-
141
- **Required Python packages** (the installer will pull these in):
142
-
143
- - `rpy2` (GPLv2 or later)
144
- - `pandas`
145
- - `numpy`
146
-
147
- ---
148
-
149
- ## Usage
150
-
151
- ```python
152
- from pathlib import Path
153
- from rpy_bridge import RFunctionCaller
154
-
155
- rfc = RFunctionCaller(
156
- path_to_renv=Path("/path/to/project"),
157
- script=Path("/path/to/script.R"),
158
- )
159
-
160
- summary_df = rfc.call("summarize_cohort", cohort_df)
161
- ```
162
-
163
- ---
164
-
165
- ## Round-trip Python ↔ R behavior
166
-
167
- `rpy-bridge` attempts to convert Python objects to R and back. Most objects used in scientific/ML pipelines round-trip cleanly, but some heterogeneous Python structures may be wrapped or slightly altered. This is normal due to R's type system.
168
-
169
- | Python type | Round-trip fidelity | Notes |
170
- | ---------------------------------------------- | ------------------- | --------------------------------------------------------------------- |
171
- | `int`, `float`, `bool`, `str` | ✅ High | Scalars convert directly |
172
- | Homogeneous `list` of numbers/strings/booleans | ✅ High | Converted to atomic R vectors |
173
- | Nested lists of homogeneous types | ✅ High | Converted to nested R `ListVector` |
174
- | `pandas.DataFrame` / `pd.Series` | ✅ High | Converted to `data.frame` / R vector, post-processed back |
175
- | Mixed-type `list` or heterogeneous `dict` | ⚠️ Partial | Elements wrapped in single-element vectors; round-trip may alter type |
176
- | Python `None` / `pd.NA` | ✅ High | Converted to R `NULL` |
177
-
178
- # Guidance
179
-
180
- - Typical workflows (DataFrames, numeric arrays, series, homogeneous lists) are fully supported.
181
- - Rare or highly heterogeneous Python objects may not round-trip perfectly.
182
- - Round-trip fidelity is mainly a “nice-to-have” for debugging. For production pipelines, it’s safe to focus on supported types.
183
-
184
- ---
185
-
186
- ## Examples
187
-
188
- ### Basic — run a local R script
189
-
190
- ```python
191
- from pathlib import Path
192
- from rpy_bridge import RFunctionCaller
193
-
194
- project_dir = Path("/path/to/your-r-project")
195
- script = project_dir / "scripts" / "example.R"
196
-
197
- caller = RFunctionCaller(path_to_renv=project_dir, script_path=script)
198
- result = caller.call("some_function", 42, named_arg="value")
199
- print(type(result))
200
- ```
201
-
202
- ### Call installed R packages (no local script)
203
-
204
- ```python
205
- from rpy_bridge import RFunctionCaller
206
-
207
- caller = RFunctionCaller(path_to_renv=None, packages=["stats"])
208
- samples = caller.call("rnorm", 5, mean=10)
209
- print(type(samples)) # typically a numpy.ndarray
210
-
211
- median_val = caller.call("stats::median", samples)
212
- print(median_val)
213
- ```
214
-
215
- ---
216
-
217
- ## R Setup
218
-
219
- If you plan to execute R code with `rpy-bridge`, use the helper scripts in
220
- `examples/r-deps/` to prepare an R environment.
221
-
222
- - On macOS (Homebrew) install system deps:
223
-
224
- ```bash
225
- bash examples/r-deps/install_r_dev_deps_homebrew.sh
226
- ```
227
-
228
- - Initialize a project `renv` (run in an R session):
229
-
230
- ```r
231
- source("examples/r-deps/setup_env.R")
232
- ```
233
-
234
- - Restore the environment on a new machine:
235
-
236
- ```r
237
- renv::restore()
238
- ```
239
-
240
- ---
241
-
242
- ## Collaboration note
243
-
244
- This repository provides example R setup scripts for teams working across Python and R. Each project may require different R packages — check the package list in `examples/r-deps/setup_env.R` and commit a `renv.lock` for project-specific reproducibility.
245
-
246
- Clone repositories containing R scripts locally or use your preferred tooling to obtain scripts before execution.
247
-
248
- ---
249
-
250
- ## Licensing
251
-
252
- - `rpy-bridge` is released under the MIT License © 2025 Victoria Cheung.
253
- - The project depends on [`rpy2`](https://rpy2.github.io) which is licensed under the GNU General Public License v2 (or later).
254
-
255
- ### Thanks
256
-
257
- This package was spun out of internal tooling at Revolution Medicines.
258
- Many thanks to the team there for allowing the code to be open sourced.
@@ -1,8 +0,0 @@
1
- rpy_bridge/__init__.py,sha256=VDCx-CiTBJO0cMp59v-gyJGBVYHjLjATTIdtYxBsK5Q,875
2
- rpy_bridge/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- rpy_bridge/rpy2_utils.py,sha256=CEH9sTiwxZwzr098JTPsAHi-DfzBKnelVThOOwgCNz8,44317
4
- rpy_bridge-0.4.0.dist-info/licenses/LICENSE,sha256=JwbWVcSfeoLfZ2M_ZiyygKVDvhBDW3zbqTWwXOJwmrA,1276
5
- rpy_bridge-0.4.0.dist-info/METADATA,sha256=Dthspg79VahggmgcS1vD68xDLk7yH8hvtJIYe1XzR-U,9639
6
- rpy_bridge-0.4.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
- rpy_bridge-0.4.0.dist-info/top_level.txt,sha256=z9UZ77ZuUPoLqMDQEpP4btstsaM1IpXb9Cn9yBVaHmU,11
8
- rpy_bridge-0.4.0.dist-info/RECORD,,