add skill: scaffold/build-r-package (renv + rocker/r-ver + DESCRIPTION)
This commit is contained in:
parent
66907fc37f
commit
356fb7fce7
18
skills/scaffold/build-r-package/DESCRIPTION.tpl
Normal file
18
skills/scaffold/build-r-package/DESCRIPTION.tpl
Normal file
@ -0,0 +1,18 @@
|
||||
Package: <package-name>
|
||||
Title: <title>
|
||||
Version: 0.1.0
|
||||
Authors@R:
|
||||
person("<author-first>", "<author-last>", email = "<author-email>", role = c("aut", "cre"))
|
||||
Description: <description>
|
||||
License: <license>
|
||||
Encoding: UTF-8
|
||||
Roxygen: list(markdown = TRUE)
|
||||
RoxygenNote: 7.3.2
|
||||
Imports:
|
||||
box
|
||||
Suggests:
|
||||
testthat (>= 3.0.0),
|
||||
lintr,
|
||||
styler,
|
||||
devtools
|
||||
Config/testthat/edition: 3
|
||||
41
skills/scaffold/build-r-package/Dockerfile.tpl
Normal file
41
skills/scaffold/build-r-package/Dockerfile.tpl
Normal file
@ -0,0 +1,41 @@
|
||||
FROM rocker/r-ver:4.4 AS base
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
libcurl4-openssl-dev \
|
||||
libssl-dev \
|
||||
libxml2-dev \
|
||||
libfontconfig1-dev \
|
||||
libharfbuzz-dev \
|
||||
libfribidi-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN install2.r --error --skipinstalled renv
|
||||
|
||||
WORKDIR /usr/<package-name>
|
||||
|
||||
ENV RENV_PATHS_LIBRARY=renv/library
|
||||
|
||||
# ── production ──────────────────────────────────────────────────────────
|
||||
FROM base AS production
|
||||
|
||||
COPY renv.lock renv.lock
|
||||
COPY renv/activate.R renv/activate.R
|
||||
|
||||
RUN R -e "renv::restore()"
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD ["R", "--vanilla", "-e", \
|
||||
"pkgload::load_all(); cat('<package-name> ready\\n')"]
|
||||
|
||||
# ── development ────────────────────────────────────────────────────────
|
||||
FROM base AS development
|
||||
|
||||
COPY renv.lock renv.lock
|
||||
COPY renv/activate.R renv/activate.R
|
||||
|
||||
RUN R -e "renv::restore()"
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD ["bash"]
|
||||
65
skills/scaffold/build-r-package/SKILL.md
Normal file
65
skills/scaffold/build-r-package/SKILL.md
Normal file
@ -0,0 +1,65 @@
|
||||
---
|
||||
name: build-r-package
|
||||
description: Scaffold a new R package with renv for dependency management, a three-stage Docker setup (base/production/development) on rocker/r-ver, docker-compose, justfile task runner, DESCRIPTION, NAMESPACE generation via roxygen2, and testthat ed. 3. Materialises files into a target directory and stops on `jj diff` for review before any commit. Use when the user says "new R package", "scaffold R package", "create R package", "set up R package", "bootstrap R package", "/build-r-package".
|
||||
---
|
||||
|
||||
# build-r-package
|
||||
|
||||
## When to use
|
||||
- User says "new R package", "scaffold R package", "/build-r-package".
|
||||
- A fresh empty directory needs the renv + rocker + DESCRIPTION setup.
|
||||
|
||||
## Inputs to collect (one grouped prompt)
|
||||
- **Package name** (letters, numbers, dots; starts with a letter; no
|
||||
trailing dot). Validate.
|
||||
- **Author name + email** for `Authors@R`.
|
||||
- **One-line title** (sentence-case, no trailing period).
|
||||
- **One-paragraph description**.
|
||||
- **License** (default: `MIT + file LICENSE`).
|
||||
|
||||
## Process
|
||||
|
||||
1. **Confirm target directory** is empty (or user-confirmed override).
|
||||
2. **Materialise files** from sibling templates:
|
||||
```
|
||||
<package>/
|
||||
├── R/<package>-package.R
|
||||
├── tests/testthat/test-<package>.R
|
||||
├── Dockerfile ← Dockerfile.tpl
|
||||
├── docker-compose.yml ← docker-compose.yml.tpl
|
||||
├── justfile ← justfile.tpl
|
||||
├── DESCRIPTION ← DESCRIPTION.tpl
|
||||
└── .gitignore ← gitignore.tpl
|
||||
```
|
||||
3. **Stop. Do not run `jj describe`.** Tell the user:
|
||||
> "Review with `jj diff`. Then run `just build-dev` → `just up` → `R
|
||||
> -e 'renv::init()'` to lock dependencies; then `just document` and
|
||||
> `just check`. Describe the change with
|
||||
> [`/jj-atomic`](../../productivity/jj-atomic/SKILL.md) when satisfied."
|
||||
4. **Suggest** `/write-readme-py`'s R counterpart once it exists (not
|
||||
yet — see octobot/README.md *Out of scope*).
|
||||
|
||||
## Placeholders used by templates
|
||||
- `<package-name>` — R package name (validated above).
|
||||
- `<author-name>`, `<author-email>` — for `Authors@R`.
|
||||
- `<title>` — one-line title.
|
||||
- `<description>` — one-paragraph description.
|
||||
- `<license>` — default `MIT + file LICENSE`.
|
||||
|
||||
## Guardrails
|
||||
- **Never** scaffold into a non-empty directory without confirmation.
|
||||
- **Never** invoke `jj describe` — first commit is the user's call.
|
||||
- **Never** invoke `renv::init()` for the user — `renv.lock` should be
|
||||
generated from inside the container so the lock matches the runtime.
|
||||
- **Never** generate `NAMESPACE` here — it's roxygen2's job, run via
|
||||
`just document` after the first edit.
|
||||
- **`R/` is empty by design** apart from `<package>-package.R`. Don't
|
||||
invent stub functions.
|
||||
|
||||
## See also
|
||||
- [`../../_concepts/three-stage-dockerfile.md`](../../_concepts/three-stage-dockerfile.md)
|
||||
— rationale for `Dockerfile.tpl`.
|
||||
- [`../../engineering/dev-r/SKILL.md`](../../engineering/dev-r/SKILL.md)
|
||||
— workflow auto-detects DESCRIPTION → R-package loop.
|
||||
- [`../../engineering/r-style/SKILL.md`](../../engineering/r-style/SKILL.md)
|
||||
— coding standards every function in `R/` must follow.
|
||||
22
skills/scaffold/build-r-package/docker-compose.yml.tpl
Normal file
22
skills/scaffold/build-r-package/docker-compose.yml.tpl
Normal file
@ -0,0 +1,22 @@
|
||||
services:
|
||||
dev:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
target: development
|
||||
container_name: <package-name>-dev
|
||||
volumes:
|
||||
- .:/usr/<package-name>
|
||||
- renv-cache:/root/.cache/R/renv
|
||||
|
||||
production:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
target: production
|
||||
container_name: <package-name>-prod
|
||||
volumes:
|
||||
- .:/usr/<package-name>
|
||||
|
||||
volumes:
|
||||
renv-cache:
|
||||
16
skills/scaffold/build-r-package/gitignore.tpl
Normal file
16
skills/scaffold/build-r-package/gitignore.tpl
Normal file
@ -0,0 +1,16 @@
|
||||
.Rproj.user
|
||||
.Rhistory
|
||||
.Rdata
|
||||
.httr-oauth
|
||||
.DS_Store
|
||||
*.Rproj
|
||||
/doc/
|
||||
/Meta/
|
||||
man/
|
||||
NAMESPACE
|
||||
renv/library/
|
||||
renv/local/
|
||||
renv/cellar/
|
||||
renv/lock/
|
||||
renv/python/
|
||||
renv/staging/
|
||||
55
skills/scaffold/build-r-package/justfile.tpl
Normal file
55
skills/scaffold/build-r-package/justfile.tpl
Normal file
@ -0,0 +1,55 @@
|
||||
# <package-name> — task runner
|
||||
# `just --list` for all recipes.
|
||||
|
||||
set dotenv-load := false
|
||||
|
||||
default:
|
||||
@just --list
|
||||
|
||||
# ── Docker ──────────────────────────────────────────────────────────────
|
||||
build-dev:
|
||||
docker compose build dev
|
||||
|
||||
build-prod:
|
||||
docker compose build production
|
||||
|
||||
up:
|
||||
docker compose run --rm dev bash
|
||||
|
||||
down:
|
||||
docker compose down
|
||||
|
||||
rebuild:
|
||||
docker compose build --no-cache dev
|
||||
|
||||
# ── Documentation ───────────────────────────────────────────────────────
|
||||
document:
|
||||
docker compose run --rm --no-deps dev Rscript -e "devtools::document()"
|
||||
|
||||
# ── Linting & Formatting ────────────────────────────────────────────────
|
||||
lint:
|
||||
docker compose run --rm --no-deps dev Rscript -e "lintr::lint_package()"
|
||||
|
||||
style:
|
||||
docker compose run --rm --no-deps dev Rscript -e "styler::style_pkg()"
|
||||
|
||||
style-check:
|
||||
docker compose run --rm --no-deps dev Rscript \
|
||||
-e "styler::style_pkg(dry = 'on')"
|
||||
|
||||
# ── Testing ─────────────────────────────────────────────────────────────
|
||||
test:
|
||||
docker compose run --rm --no-deps dev Rscript -e "devtools::test()"
|
||||
|
||||
test-verbose:
|
||||
docker compose run --rm --no-deps dev Rscript \
|
||||
-e "devtools::test(reporter = 'progress')"
|
||||
|
||||
# ── Package checks ──────────────────────────────────────────────────────
|
||||
check:
|
||||
docker compose run --rm dev Rscript -e "devtools::check()"
|
||||
|
||||
# ── Combined ────────────────────────────────────────────────────────────
|
||||
check-fast: lint style-check test
|
||||
|
||||
fix-and-check: style document check
|
||||
Loading…
x
Reference in New Issue
Block a user