rpy-bridge 0.1.0__py3-none-any.whl → 0.3.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.
- rpy_bridge/__init__.py +2 -2
- rpy_bridge/rpy2_utils.py +521 -257
- rpy_bridge-0.3.0.dist-info/METADATA +251 -0
- rpy_bridge-0.3.0.dist-info/RECORD +8 -0
- rpy_bridge-0.1.0.dist-info/METADATA +0 -205
- rpy_bridge-0.1.0.dist-info/RECORD +0 -8
- {rpy_bridge-0.1.0.dist-info → rpy_bridge-0.3.0.dist-info}/WHEEL +0 -0
- {rpy_bridge-0.1.0.dist-info → rpy_bridge-0.3.0.dist-info}/licenses/LICENSE +0 -0
- {rpy_bridge-0.1.0.dist-info → rpy_bridge-0.3.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rpy-bridge
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Bridge helpers for calling R from Python via rpy2
|
|
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
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
35
|
+
Classifier: Programming Language :: Python
|
|
36
|
+
Classifier: Programming Language :: Python :: 3
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
39
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
40
|
+
Requires-Python: >=3.11
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
License-File: LICENSE
|
|
43
|
+
Requires-Dist: numpy>=1.24
|
|
44
|
+
Requires-Dist: pandas>=2.0
|
|
45
|
+
Requires-Dist: loguru>=0.7
|
|
46
|
+
Provides-Extra: r
|
|
47
|
+
Requires-Dist: rpy2>=3.5; extra == "r"
|
|
48
|
+
Provides-Extra: dev
|
|
49
|
+
Requires-Dist: ipykernel>=7.1.0; extra == "dev"
|
|
50
|
+
Provides-Extra: docs
|
|
51
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
52
|
+
Requires-Dist: myst-parser; extra == "docs"
|
|
53
|
+
Dynamic: license-file
|
|
54
|
+
|
|
55
|
+
# rpy-bridge
|
|
56
|
+
|
|
57
|
+
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.
|
|
58
|
+
|
|
59
|
+
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.
|
|
60
|
+
|
|
61
|
+
**Latest release:** [`rpy-bridge` on PyPI](https://pypi.org/project/rpy-bridge/)
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Key layers and capabilities
|
|
66
|
+
|
|
67
|
+
### 1. Lazy and robust R integration
|
|
68
|
+
|
|
69
|
+
- Automatically detects or sets R_HOME and ensures rpy2 is installed.
|
|
70
|
+
- Configures platform-specific dynamic library paths for macOS/Linux.
|
|
71
|
+
|
|
72
|
+
### 2. Environment management
|
|
73
|
+
|
|
74
|
+
- Activates renv projects and loads project-specific libraries if it exists, otherwise use current environemnt.
|
|
75
|
+
- Sources .Renviron and .Rprofile files to replicate the R project environment in Python.
|
|
76
|
+
|
|
77
|
+
### 3. Python ↔ R type conversion
|
|
78
|
+
|
|
79
|
+
- Converts Python scalars, lists, dicts, and pandas DataFrames into appropriate R objects.
|
|
80
|
+
- Converts R atomic vectors, ListVector/NamedList, and data.frames back into Python-native objects.
|
|
81
|
+
- Handles nested structures, mixed types, and missing values robustly (NA_* → None/pd.NA).
|
|
82
|
+
|
|
83
|
+
### 4. Data hygiene and normalization
|
|
84
|
+
|
|
85
|
+
- Post-processes R DataFrames: fixes dtypes, numeric/date conversions, and timezone issues.
|
|
86
|
+
- Normalizes and aligns column types for accurate Python comparisons.
|
|
87
|
+
- Supports comparing Python and R DataFrames with mismatch diagnostics.
|
|
88
|
+
|
|
89
|
+
### 5. Function calling
|
|
90
|
+
|
|
91
|
+
- Calls functions from R scripts, base R, or installed packages safely.
|
|
92
|
+
- Automatically converts arguments and return values, including keyword arguments.
|
|
93
|
+
- Supports mixed data types, nested structures, and DataFrames seamlessly.
|
|
94
|
+
|
|
95
|
+
### 6. Python-first workflow for R code
|
|
96
|
+
|
|
97
|
+
- Enables Python developers to reuse R functions without needing deep R knowledge.
|
|
98
|
+
- Keeps network, token, and SSL concerns outside the package when sourcing scripts locally.
|
|
99
|
+
- Designed for reproducibility and safe execution in CI or cross-platform environments.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Installation
|
|
104
|
+
|
|
105
|
+
**Prerequisites**
|
|
106
|
+
|
|
107
|
+
- System R installed and available on `PATH` (rpy2 requires a working R installation).
|
|
108
|
+
- Python 3.12+
|
|
109
|
+
|
|
110
|
+
**From PyPI:**
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
python3 -m pip install rpy-bridge
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
or using `uv`:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
uv add rpy-bridge
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**During development (editable install):**
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
python3 -m pip install -e .
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
or using `uv`:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
uv sync
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**Required Python packages** (the installer will pull these in):
|
|
135
|
+
|
|
136
|
+
- `rpy2` (GPLv2 or later)
|
|
137
|
+
- `pandas`
|
|
138
|
+
- `numpy`
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Usage
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from pathlib import Path
|
|
146
|
+
from rpy_bridge import RFunctionCaller
|
|
147
|
+
|
|
148
|
+
caller = RFunctionCaller(
|
|
149
|
+
path_to_renv=Path("/path/to/project"),
|
|
150
|
+
script_path=Path("/path/to/script.R"),
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
summary_df = caller.call("summarize_cohort", cohort_df)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Round-trip Python ↔ R behavior
|
|
159
|
+
|
|
160
|
+
`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.
|
|
161
|
+
|
|
162
|
+
| Python type | Round-trip fidelity | Notes |
|
|
163
|
+
| ---------------------------------------------- | ------------------- | --------------------------------------------------------------------- |
|
|
164
|
+
| `int`, `float`, `bool`, `str` | ✅ High | Scalars convert directly |
|
|
165
|
+
| Homogeneous `list` of numbers/strings/booleans | ✅ High | Converted to atomic R vectors |
|
|
166
|
+
| Nested lists of homogeneous types | ✅ High | Converted to nested R `ListVector` |
|
|
167
|
+
| `pandas.DataFrame` / `pd.Series` | ✅ High | Converted to `data.frame` / R vector, post-processed back |
|
|
168
|
+
| Mixed-type `list` or heterogeneous `dict` | ⚠️ Partial | Elements wrapped in single-element vectors; round-trip may alter type |
|
|
169
|
+
| Python `None` / `pd.NA` | ✅ High | Converted to R `NULL` |
|
|
170
|
+
|
|
171
|
+
# Guidance
|
|
172
|
+
|
|
173
|
+
- Typical workflows (DataFrames, numeric arrays, series, homogeneous lists) are fully supported.
|
|
174
|
+
- Rare or highly heterogeneous Python objects may not round-trip perfectly.
|
|
175
|
+
- Round-trip fidelity is mainly a “nice-to-have” for debugging. For production pipelines, it’s safe to focus on supported types.
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Examples
|
|
180
|
+
|
|
181
|
+
### Basic — run a local R script
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
from pathlib import Path
|
|
185
|
+
from rpy_bridge import RFunctionCaller
|
|
186
|
+
|
|
187
|
+
project_dir = Path("/path/to/your-r-project")
|
|
188
|
+
script = project_dir / "scripts" / "example.R"
|
|
189
|
+
|
|
190
|
+
caller = RFunctionCaller(path_to_renv=project_dir, script_path=script)
|
|
191
|
+
result = caller.call("some_function", 42, named_arg="value")
|
|
192
|
+
print(type(result))
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Call installed R packages (no local script)
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
from rpy_bridge import RFunctionCaller
|
|
199
|
+
|
|
200
|
+
caller = RFunctionCaller(path_to_renv=None, packages=["stats"])
|
|
201
|
+
samples = caller.call("rnorm", 5, mean=10)
|
|
202
|
+
print(type(samples)) # typically a numpy.ndarray
|
|
203
|
+
|
|
204
|
+
median_val = caller.call("stats::median", samples)
|
|
205
|
+
print(median_val)
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## R Setup
|
|
211
|
+
|
|
212
|
+
If you plan to execute R code with `rpy-bridge`, use the helper scripts in
|
|
213
|
+
`examples/r-deps/` to prepare an R environment.
|
|
214
|
+
|
|
215
|
+
- On macOS (Homebrew) install system deps:
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
bash examples/r-deps/install_r_dev_deps_homebrew.sh
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
- Initialize a project `renv` (run in an R session):
|
|
222
|
+
|
|
223
|
+
```r
|
|
224
|
+
source("examples/r-deps/setup_env.R")
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
- Restore the environment on a new machine:
|
|
228
|
+
|
|
229
|
+
```r
|
|
230
|
+
renv::restore()
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Collaboration note
|
|
236
|
+
|
|
237
|
+
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.
|
|
238
|
+
|
|
239
|
+
Clone repositories containing R scripts locally or use your preferred tooling to obtain scripts before execution.
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Licensing
|
|
244
|
+
|
|
245
|
+
- `rpy-bridge` is released under the MIT License © 2025 Victoria Cheung.
|
|
246
|
+
- The project depends on [`rpy2`](https://rpy2.github.io) which is licensed under the GNU General Public License v2 (or later).
|
|
247
|
+
|
|
248
|
+
### Thanks
|
|
249
|
+
|
|
250
|
+
This package was spun out of internal tooling at Revolution Medicines.
|
|
251
|
+
Many thanks to the team there for allowing the code to be open sourced.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
rpy_bridge/__init__.py,sha256=fXINFO0OFsSkxNccFPlSPIVsye5WGLVzu6Puf7o1Ao4,829
|
|
2
|
+
rpy_bridge/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
rpy_bridge/rpy2_utils.py,sha256=D8hCv9axFbHGM71NFNO6E4oZIIBA5fBioOvzLDEVAHM,27842
|
|
4
|
+
rpy_bridge-0.3.0.dist-info/licenses/LICENSE,sha256=JwbWVcSfeoLfZ2M_ZiyygKVDvhBDW3zbqTWwXOJwmrA,1276
|
|
5
|
+
rpy_bridge-0.3.0.dist-info/METADATA,sha256=OiXICUzyvUtULJfEfxphdFRQdk_ApD9vf7nwcuDAJ5I,9178
|
|
6
|
+
rpy_bridge-0.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
+
rpy_bridge-0.3.0.dist-info/top_level.txt,sha256=z9UZ77ZuUPoLqMDQEpP4btstsaM1IpXb9Cn9yBVaHmU,11
|
|
8
|
+
rpy_bridge-0.3.0.dist-info/RECORD,,
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: rpy-bridge
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: Bridge helpers for calling R from Python via rpy2
|
|
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
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
35
|
-
Classifier: Programming Language :: Python
|
|
36
|
-
Classifier: Programming Language :: Python :: 3
|
|
37
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
38
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
39
|
-
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
40
|
-
Requires-Python: >=3.11
|
|
41
|
-
Description-Content-Type: text/markdown
|
|
42
|
-
License-File: LICENSE
|
|
43
|
-
Requires-Dist: numpy>=1.24
|
|
44
|
-
Requires-Dist: pandas>=2.0
|
|
45
|
-
Requires-Dist: rpy2>=3.5
|
|
46
|
-
Requires-Dist: loguru>=0.7
|
|
47
|
-
Requires-Dist: ipykernel>=7.1.0
|
|
48
|
-
Dynamic: license-file
|
|
49
|
-
|
|
50
|
-
# rpy-bridge
|
|
51
|
-
|
|
52
|
-
Utilities for calling R code from Python using `rpy2`. It provides a small
|
|
53
|
-
wrapper that can (optionally) activate an `renv` project, source an R
|
|
54
|
-
script, call functions from that script, and post-process results into
|
|
55
|
-
well-typed pandas `DataFrame` objects.
|
|
56
|
-
|
|
57
|
-
This project was developed for bilingual teams where some functions are
|
|
58
|
-
authored in R and the primary consumer is a Python-centric developer. It
|
|
59
|
-
acts as an interoperability layer so a Python programmer can call and reuse
|
|
60
|
-
R functions (written and maintained by R authors) without reimplementing
|
|
61
|
-
that logic in Python.
|
|
62
|
-
|
|
63
|
-
## Installation
|
|
64
|
-
|
|
65
|
-
Prerequisites
|
|
66
|
-
|
|
67
|
-
- System R installed and available on `PATH` (rpy2 requires a working R
|
|
68
|
-
installation).
|
|
69
|
-
- Python 3.12+
|
|
70
|
-
|
|
71
|
-
Installation
|
|
72
|
-
|
|
73
|
-
Install from PyPI or as an editable local package during development:
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
# From PyPI (recommended for consumers)
|
|
77
|
-
python3 -m pip install rpy-bridge
|
|
78
|
-
|
|
79
|
-
# During development (install editable from local source)
|
|
80
|
-
python3 -m pip install -e .
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
Required Python packages (the installer will pull these in):
|
|
84
|
-
|
|
85
|
-
- `rpy2` (GPLv2 or later)
|
|
86
|
-
- `pandas`
|
|
87
|
-
- `numpy`
|
|
88
|
-
|
|
89
|
-
## Usage
|
|
90
|
-
|
|
91
|
-
```python
|
|
92
|
-
from pathlib import Path
|
|
93
|
-
|
|
94
|
-
from rpy_bridge import RFunctionCaller
|
|
95
|
-
|
|
96
|
-
caller = RFunctionCaller(
|
|
97
|
-
path_to_renv=Path("/path/to/project"),
|
|
98
|
-
script_path=Path("/path/to/script.R"),
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
summary_df = caller.call("summarize_cohort", cohort_df)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
## Examples
|
|
105
|
-
|
|
106
|
-
Basic — run a local R script
|
|
107
|
-
|
|
108
|
-
```python
|
|
109
|
-
from pathlib import Path
|
|
110
|
-
from rpy_bridge import RFunctionCaller
|
|
111
|
-
|
|
112
|
-
# If your project uses renv, pass the project directory (parent of renv/)
|
|
113
|
-
project_dir = Path("/path/to/your-r-project")
|
|
114
|
-
script = project_dir / "scripts" / "example.R"
|
|
115
|
-
|
|
116
|
-
# If you do not use renv, pass None for path_to_renv
|
|
117
|
-
caller = RFunctionCaller(path_to_renv=project_dir, script_path=script)
|
|
118
|
-
result = caller.call("some_function", 42, named_arg="value")
|
|
119
|
-
print(type(result))
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Notes:
|
|
123
|
-
|
|
124
|
-
`path_to_renv` may be either the project directory (containing `renv/`) or
|
|
125
|
-
the `renv/` directory itself. When provided, `RFunctionCaller` will call
|
|
126
|
-
`renv::load()` so the R session uses the project's library versions. If
|
|
127
|
-
`path_to_renv` is `None`, `rpy-bridge` will use whatever R environment is
|
|
128
|
-
visible to the Python process (system R or an R environment you activated
|
|
129
|
-
before starting Python).
|
|
130
|
-
|
|
131
|
-
The intended workflow is:
|
|
132
|
-
|
|
133
|
-
- Clone or download the R script into your local filesystem (review the
|
|
134
|
-
code if it came from a remote source).
|
|
135
|
-
- Construct an `RFunctionCaller` with `script_path` pointing to the local
|
|
136
|
-
script and optionally `path_to_renv` to activate the project's R library.
|
|
137
|
-
|
|
138
|
-
This keeps network, token, and SSL concerns outside the package while
|
|
139
|
-
preserving an easy path for Python-first users to call R-written functions.
|
|
140
|
-
|
|
141
|
-
If you need to run an R script from a remote repository, clone or download
|
|
142
|
-
the script locally, review it, and then construct an `RFunctionCaller`
|
|
143
|
-
pointing at the local `script_path`. This keeps network, token, and SSL
|
|
144
|
-
concerns outside the package and avoids environment-specific failures.
|
|
145
|
-
|
|
146
|
-
```python
|
|
147
|
-
from rpy_bridge import RFunctionCaller
|
|
148
|
-
|
|
149
|
-
project_dir = Path("/path/to/cloned/repo")
|
|
150
|
-
script = project_dir / "scripts" / "analysis.R"
|
|
151
|
-
|
|
152
|
-
caller = RFunctionCaller(path_to_renv=None, script_path=script)
|
|
153
|
-
result = caller.call("analyze", some_arg=42)
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
## R Setup
|
|
157
|
-
|
|
158
|
-
If you plan to execute R code with `rpy-bridge`, use the helper scripts in
|
|
159
|
-
`examples/r-deps/` to prepare an R environment.
|
|
160
|
-
|
|
161
|
-
- On macOS (Homebrew) install system deps:
|
|
162
|
-
|
|
163
|
-
```bash
|
|
164
|
-
bash examples/r-deps/install_r_dev_deps_homebrew.sh
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
- Initialize a project `renv` (run in an R session):
|
|
168
|
-
|
|
169
|
-
```r
|
|
170
|
-
source("examples/r-deps/setup_env.R")
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
- Restore the environment on a new machine:
|
|
174
|
-
|
|
175
|
-
```r
|
|
176
|
-
renv::restore()
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
Review the scripts in `examples/r-deps/` before running; they install system
|
|
180
|
-
libraries and R packages and should be run from a trusted environment. For
|
|
181
|
-
CI, use `r-lib/actions/setup-r` to install R, then run the `Rscript` command
|
|
182
|
-
above to prepare the `renv` environment.
|
|
183
|
-
|
|
184
|
-
## Collaboration note
|
|
185
|
-
|
|
186
|
-
This repository provides example R setup scripts for teams working across
|
|
187
|
-
Python and R. Each project may require different R packages — check the
|
|
188
|
-
package list in `examples/r-deps/setup_env.R` and commit a `renv.lock` for
|
|
189
|
-
project-specific reproducibility.
|
|
190
|
-
|
|
191
|
-
Clone repositories containing R scripts locally or use your
|
|
192
|
-
preferred tooling to obtain scripts before execution.
|
|
193
|
-
|
|
194
|
-
## Licensing
|
|
195
|
-
|
|
196
|
-
- `rpy-bridge` is released under the MIT License © 2025 Victoria Cheung.
|
|
197
|
-
- The project depends on [`rpy2`](https://rpy2.github.io) which is licensed
|
|
198
|
-
under the GNU General Public License v2 (or later). Distributing binaries that
|
|
199
|
-
bundle `rpy2` must comply with the GPL terms. When you install `rpy-bridge`
|
|
200
|
-
as a dependency, `rpy2` is resolved directly from its upstream maintainers.
|
|
201
|
-
|
|
202
|
-
### Thanks
|
|
203
|
-
|
|
204
|
-
This package was spun out of internal tooling at Revolution Medicines.
|
|
205
|
-
Many thanks to the team there for allowing the code to be open sourced.
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
rpy_bridge/__init__.py,sha256=56cw27pgg7ES9zl6-rwKz01Ky3MRvJX2dusBAjbGXM4,823
|
|
2
|
-
rpy_bridge/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
rpy_bridge/rpy2_utils.py,sha256=13BDM0577R4cjZ06CSH0Glv0xkA9ZbaTe4gS9eno_ko,20536
|
|
4
|
-
rpy_bridge-0.1.0.dist-info/licenses/LICENSE,sha256=JwbWVcSfeoLfZ2M_ZiyygKVDvhBDW3zbqTWwXOJwmrA,1276
|
|
5
|
-
rpy_bridge-0.1.0.dist-info/METADATA,sha256=t7wkdtOKNvB4Ty2oPajgoJiqw88FW0AgTdaSDca4Jew,7229
|
|
6
|
-
rpy_bridge-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
-
rpy_bridge-0.1.0.dist-info/top_level.txt,sha256=z9UZ77ZuUPoLqMDQEpP4btstsaM1IpXb9Cn9yBVaHmU,11
|
|
8
|
-
rpy_bridge-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|