Skip to content
Skills Library
Programming · Conversion & formats

python-port-from-r

/python-port-from-r

Port an R (or other-language) script to Python without changing results: inventory behaviour, keep CLI and output layout, reproduce quirks such as NA handling and ID derivation, add equivalence tests on the same input, and document deviations. Use when replacing R scripts by stdlib or pandas Python, e.g. for production servers.

Licence
MIT
Last repository change
11.11.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 11.11.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Port an R (or other-language) script to Python without changing results: inventory behaviour, keep CLI and output layout, reproduce quirks such as NA handling and ID derivation, add equivalence tests on the same input, and document deviations. Use when replacing R scripts by stdlib or pandas Python, e.g. for production servers.

Original author description

Port an R (or other-language) script to Python without changing results: inventory behaviour, keep CLI and output layout, reproduce quirks such as NA handling and ID derivation, add equivalence tests on the same input, and document deviations. Use when replacing R scripts by stdlib or pandas Python, e.g. for production servers.

How it works

  1. When to use / not to use
  2. Steps
  3. Example of a mirrored quirk
  4. Checks before finishing
  5. Pitfalls
Original SKILL.md headings · 46 lines, 443 words
SKILL.md preview
---
name: python-port-from-r
description: 'Port an R (or other-language) script to Python without changing results: inventory behaviour, keep CLI and output layout, reproduce quirks such as NA handling and ID derivation, add equivalence tests on the same input, and document deviations. Use when replacing R scripts by stdlib or pandas Python, e.g. for production servers.'
---

# Port a script to Python, behaviour-equivalent

Purpose: replace the language, not the results. A silent change in output can reach a patient or a
published number.

## When to use / not to use

Use for a faithful port. A redesign or a threshold fix is a separate, result-affecting change: ask
first, one commit each (workspace rules apply).

## Steps

1. **Inventory the original.** List inputs, CLI arguments, defaults, outputs (names, columns, order, sorting, number formatting), checks and error texts, and quirks: `read.delim` treats only the literal `NA` as missing, factor ordering, 1- vs 0-based indices, rounding, locale-dependent sorting, hashing of IDs.
2. **Freeze reference output.** Run the R script on a small synthetic input (or an approved tiny slice) and keep the outputs outside the repo or as test fixtures. Never use real patient data as fixture.
3. **Keep the interface.** Same CLI, same checks, same output layout, so callers do not change (record this sentence in the docstring: "kept behaviourally equivalent: same CLI, same checks, same output layout"). Name the original: "Port of `<script>.R`".
4. **Choose dependencies by target.** Production server: stdlib only (`csv`, `json`, `argparse`, `pathlib`). Pipeline env: pandas allowed. Do not add a dependency just to mimic one R function; write a small helper with a docstring noting the R behaviour it mirrors (e.g. `as_missing`).
5. **Write the port** with `python-bin-script`; keep IDs derived identically (e.g. the same sha256 input string) so identifiers stay stable.
6. **Equivalence tests.** Run old and new on the same inputs, normalize volatile fields, diff record by record, and show the diff. Cover edge cases: empty input, missing column, NA values, whitespace, odd characters. A test per deviation.
7. **Document deviations** (anything not byte-identical, with reason) in the docstring, `CHANGELOG.md` and the commit message. Mark the change as AI-assisted the way the project does.
8. **Keep the R script until the diff is clean** and the user agrees to remove it.

## Example of a mirrored quirk

```python
NA_TOKEN = "NA"

def as_missing(value):
    """Mirror R's read.delim default: only the literal text 'NA' is missing."""
    return None if value == NA_TOKEN else value
```

Empty strings stay empty strings, as in the original; a test pins this.

## Checks before finishing

- Equivalence diff is empty, or every difference is listed and approved.
- Error behaviour matches (same inputs rejected, exit non-zero).
- Docs and workflow call sites updated; the old script is not silently left running.

## Pitfalls

- Floating-point formatting (`format`/`round` differences): compare numerically with a stated tolerance.
- Sorting differences from locale or stable vs unstable sort.
- Treating an R quirk as a bug and fixing it during the port.

Versions

The database has no other skills named python-port-from-r.

Database snapshot: 13.11.2026 · package version dbf3a85fdd50 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 4 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 90port-python-parity
    Port features from the official Python claude-agent-sdk to this Ruby gem for parity. Use when syncing with a new Python SDK release, running a gap analysis, or batching parity fixes.
  • 100python-stdlib-orchestration
    Write stdlib-only orchestration scripts for production servers: idempotent submit/readiness logic with a locked atomic JSON state file, readiness judged from real outputs, pre-submission input checks, --dry-run and --force, blocked status with exit code 2, and a bash-and-Python…
  • 100zimanyar-port-from-zimankit
    Port a zimankit (Python) function or module to @zimanyar/core (TypeScript) with identical behaviour, proven by parity fixtures exported with uv. Use for any work in packages/core that mirrors zimankit, and when a parity test fails.
  • 95port-from-python
    Port Python into Rust — construct mapping, the semantic traps (integer width, floor division, str versus bytes, exceptions to Result), and the seam, which is a process boundary for a standalone replacement and PyO3 when Python keeps calling the code. Use when porting, rewriting,…
  • 95build-agent-python
    Python build agent for scripts, backends, data pipelines, and ML projects. Extends build-agent with Python conventions. Use when building Python applications, APIs, data processing, or automation.
  • 100rust-port
    Port code from C, C++, Python, Go, JavaScript, or TypeScript into idiomatic Rust that keeps the original behavior: ownership instead of manual memory, Result instead of error codes and exceptions, enums instead of flag ints and magic strings, and tests that prove the port…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.