用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/Morrison-Lab/ai-config --skill reprexes命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | reprexes |
| description | Build minimal reproducible example. |
| user-invocable | true |
| allowed-tools | ["Bash","Read","Write","Edit"] |
When a technical problem is hard to pin down, don't debug it in the full context of the motivating application. Extract a minimal, self-contained reproduction of the phenomenon, iterate candidate fixes on that (a fast, clean loop), then port the working fix back to the real code.
Reference: https://r4ds.hadley.nz/workflow-help.html#making-a-reprex. The payoff is real: often, the act of building a thorough reprex surfaces the cause on its own — the noise you strip away was hiding it.
quarto render — where each reproduction attempt is slow.Don't bother for a one-line obvious fix, or a problem you can already see and test cheaply in place.
A reprex is only useful if it is BOTH:
library() call, and code that creates every object it
uses. Someone (or a fresh session) can run it cold and see the same thing.The tension between these two is the whole game: include enough to reproduce, but nothing more.
Hypothesize the minimal trigger. What is the smallest combination of data + operation you believe causes the phenomenon?
Create a standalone scratch file outside the repo tree (e.g.
/tmp/reprex.R, or a tiny /tmp/reprex.qmd for a render bug; on a
non-Unix machine use tempfile(fileext = ".R") / tempdir() for a
portable path). Put in it, in order:
library(...)),Run it in a clean session and confirm it reproduces. For R, run with
Rscript --vanilla /tmp/reprex.R (a fresh process; --vanilla skips
.Rprofile/.Renviron so no stale globalenv() state or profile settings
mask or fake the bug). For a Quarto page, render just that file:
quarto render /tmp/reprex.qmd --to html, not the whole site.
Minimize. Remove pieces until the phenomenon disappears — the last removal that "fixes" it implicates that piece. (Or build up from nothing until it appears.) Keep the data as small as it can be while still failing.
Iterate fixes on the reprex, not the full app. This is the fast loop the whole technique exists to create.
Port the fix back to the real code and verify it there.
Clean up. Delete the scratch file (it lives in /tmp, so it never
touches the repo). If the bug was subtle, consider promoting the reprex
into a real regression test (testthat) instead of discarding it.
mtcars, mpg) or a hand-built
tiny frame over the real data.dput() so the reprex recreates it inline — no external file dependency.In R packages and Quarto projects, reprexes are usually short R snippets or
a single standalone .qmd page. Respect the repo's lint config if the
reprex code will be ported back.
The reprex package (tidyverse, https://reprex.tidyverse.org/)
formats a reprex for sharing: it runs your code in a clean, separate R
session (via callr) and emits code plus actual
output.
Copy the code and call reprex::reprex() (reads the clipboard by default),
or point it at a file with reprex::reprex(input = "/tmp/reprex.R") (or a
tempfile(fileext = ".R") path on non-Unix machines) — handy from a
non-interactive CLI session where there's no clipboard. Use it when the
output is destined for a PR comment or an upstream issue. Useful arguments:
venue = — output format:
"gh" — GitHub-flavored Markdown (default)"so" / "ds" — Stack Overflow / Discourse"slack" — Slack message"r" — runnable R script with commented output"html" — HTML"rtf" — rich text for presentationssession_info = TRUE — append sessionInfo() / sessioninfo::session_info(),
so versions travel with the reprex (set this when the bug may be
version-dependent).
std_out_err = TRUE — capture stdout/stderr too (e.g. system() /
subprocess or C-level output that doesn't come back as normal R results).
wd = — set the working directory when the code needs one.
Validation bonus: because reprex::reprex() runs in a fresh session, if it errors
on a missing object or package, your example wasn't actually
self-contained — fix that before sharing.
Companion helpers handle "wild-caught" reprexes (all exported in reprex
2.x): reprex::reprex_clean() (strip the #> output markers from a
rendered/pasted reprex, leaving runnable code), reprex::reprex_rescue()
(recover code from R-console output with >/+ prompts), and
(the inverse of — recover the
input code from a rendered reprex).
/tmp (or tempdir() on
non-Unix machines) or a gitignored scratch path.reprex::reprex_invert()reprex::reprex()When the bug might be version-dependent, capture sessionInfo() (or set
session_info = TRUE above) in the reprex so versions are part of the
record. If you suspect stale packages are the cause,
tidyverse::tidyverse_update() outside the reprex can rule that out — but it
updates packages, it doesn't
record versions, so don't put it in the reprex itself.
Build artifacts (_site/, _freeze/, .quarto/) are common confounders
for "it renders differently" bugs — a clean standalone render sidesteps
stale freeze caches.