agentleFS
SaehwanParkSaehwanPark/agent-skills-archive/skills/call-r-lib-in-python/SKILL.md

call-r-lib-in-python

Skill1 starsChanged 5 months agoMITView on GitHub

Use when Python must call an R package through rpy2, exchange pandas or NumPy data with R, fit R-native models, or diagnose R discovery, package-library, conversion, and result-extraction failures.

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 5 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use rpy2 when an R-only implementation is required in-process.

    line 8
  2. Distinctive:

    Before debugging bridge code, verify the same environment that launches Python can run:

    line 14
  3. Very specific:

    Check packages with requireNamespace(..., quietly = TRUE) and use namespace-qualified calls where practical.

    line 31
  4. Distinctive:

    Read integration patterns for concrete rpy2 code.

    line 45
  5. Distinctive:

    Read troubleshooting only when diagnosing a failure.

    line 46
  6. Distinctive:

    Treat these as public boundary concerns:

    line 54
  7. Distinctive:

    Stop and report when:

    line 63

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Call R Libraries from Python

Use rpy2 when an R-only implementation is required in-process. Prefer a maintained Python-native implementation when it satisfies the requirement; prefer an Rscript subprocess when strict process or dependency isolation is necessary.

Preflight

Before debugging bridge code, verify the same environment that launches Python can run:

which R
R --version
python -c "import rpy2; print(rpy2.__version__)"

Resolve R discovery, compatible R/rpy2 versions, and native build prerequisites before investigating packages or conversion. Do not set R_HOME unless the installed rpy2/R configuration requires it.

Integration workflow

  1. Choose and document a reproducible R dependency strategy. If packages are installed at runtime, use a writable project-local library and configure .libPaths() before package lookup. Do not silently mutate a global R installation.
  2. Check packages with requireNamespace(..., quietly = TRUE) and use namespace-qualified calls where practical. Installation is an explicit environment/setup action, not an incidental model-fitting side effect.
  3. Convert data explicitly at the Python/R boundary with a scoped rpy2 converter. Keep the original R object when R semantics such as factors, formulas, attributes, or classes matter.
  4. Fit models with R-native inputs. Represent domain responses correctly—for example, grouped binomial models use successes and failures rather than an unexplained raw proportion.
  5. Extract stable, named results at the R boundary. Coerce optional NULL values and complex S3/S4 structures in R before converting them to Python.
  6. Return typed Python-facing values and retain version, warning, convergence, and failure evidence needed to interpret the result.

Read integration patterns for concrete rpy2 code. Read troubleshooting only when diagnosing a failure.

Design boundaries

Separate runtime discovery, dependency setup, conversion, and analysis. Keep R evaluation small and parameterized; do not interpolate untrusted values into R source strings. Prefer rpy2 objects, function calls, and explicit assignment over constructing executable code.

Treat these as public boundary concerns:

  • Missing R, packages, compilers, or system libraries.
  • Data-frame column types, missing values, factors, dates, and index semantics.
  • R warnings, convergence messages, NULL, S3/S4 objects, and scalar/vector shape.
  • Reproducible package versions and repositories.

Stop conditions

Stop and report when:

  • R and rpy2 compatibility cannot be established from the active environment.
  • Package installation needs system changes, credentials, or network access not authorized by the user.
  • Conversion would discard domain-significant R attributes or classes.
  • A model result cannot be extracted without relying on an undocumented package structure.

Completion checklist

  • R discovery and relevant versions were recorded.
  • Dependency setup is explicit and reproducible.
  • Conversions are scoped and tested in both directions where required.
  • R-native semantics are preserved during fitting and extraction.
  • Warnings, optional values, and failures have stable Python representations.
  • Tests cover representative data, missing/empty input, and at least one failure boundary.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.