Skip to main content
skill CX Codex

r-package-development — Claude Code skill for R package work

A skill that tells the agent how to work on an R package: testthat tests, roxygen2 docs, R CMD check and NEWS.md entries.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add posit-dev/skills --skill r-package-development -a claude-code
Open on GitHub

What r-package-development does

The skill sets the rules an agent follows while working on an R package built with devtools, testthat and roxygen2. It ships a command list the agent runs through Rscript -e: load the package code, run the full test suite, filter tests by file name prefix, run tests for a single file or a single named test, redocument the package, check pkgdown and run devtools::check().

Separate sections cover coding, testing, documentation and NEWS.md. After generating code the agent must run air format .. Code uses the base pipe |> instead of %>%, and single-line anonymous functions are written as \() .... Tests for R/{name}.R belong in tests/testthat/test-{name}.R, and new code is expected to come with a test. Errors and warnings are checked with expect_snapshot(error = TRUE) and expect_snapshot() rather than expect_error() and expect_warning().

You need R installed along with devtools, testthat, roxygen2 and pkgdown, and formatting depends on the external air tool — skip that and the format step fails. Roxygen comments wrap at 80 characters, every new topic goes into _pkgdown.yml, and any edit to a roxygen comment means the package gets redocumented.

What it helps with

  • run tests for one package file and read the failure
  • redocument the package after editing roxygen comments
  • add a test for a new function in the right tests/testthat file
  • check the package with R CMD check before release
  • record a user-facing change as a NEWS.md bullet

Example prompts for the agent

  • run the tests for R/utils.R and show me what broke
  • add roxygen2 docs for the new exported function
  • add a NEWS.md entry and redocument the package

How to install r-package-development

1Skills CLI (Vercel)

npx skills add posit-dev/skills --skill r-package-development -a claude-code

2Manually: put the files in place

~/.claude/skills/r-package-development/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/r-package-development/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about r-package-development

How do I install r-package-development in Claude?

Run npx skills add posit-dev/skills --skill r-package-development -a claude-code. The skill lands in ~/.claude/skills/r-package-development/SKILL.md.

What does r-package-development do?

It tells the agent how to develop an R package: run testthat tests, build roxygen2 documentation, check the package and update NEWS.md.

What do I need for this skill to work?

R with devtools, testthat, roxygen2 and pkgdown installed. Code formatting runs through the air format . tool, so it has to be available on your system.

Source text

SKILL.md · MIT
---
name: r-package-development
description: R package development with devtools, testthat, and roxygen2. Use when the user is working on an R package, running tests, writing documentation, or building package infrastructure.
metadata:
  author: Simon P. Couch (@simonpcouch)
  version: "1.2"
---

# R package development

## Key commands

```
# Run code in the package
Rscript -e "devtools::load_all(); code"

# Run all tests
Rscript -e "devtools::test()"

# Run all tests for files starting with {name}
Rscript -e "devtools::test(filter = '^{name}')"

# Run all tests for R/{name}.R
Rscript -e "devtools::test_active_file('R/{name}.R')"

# Run a single test "blah" for R/{name}.R
Rscript -e "devtools::test_active_file('R/{name}.R', desc = 'blah')"

# Redocument the package
Rscript -e "devtools::document()"

# Check pkgdown documentation
Rscript -e "pkgdown::check_pkgdown()"

# Check the package with R CMD check
Rscript -e "devtools::check()"

# Format code
air format .
```

## Coding

* Always run `air format .` after generating code.
* Use the base pipe operator (`|>`) not the magrittr pipe (`%>%`).
* Use `\() ...` for single-line anonymous functions. For all other cases, use `function() {...}`.

## Testing

- Tests for `R/{name}.R` go in `tests/testthat/test-{name}.R`.
- All new code should have an accompanying test.
- If there are existing tests, place new tests next to similar existing tests.
- Strive to keep tests minimal with few comments.
- Avoid `expect_true()` and `expect_false()` in favour of a specific expectation which will give a better failure message.
- When testing errors and warnings, don't use `expect_error()` or `expect_warning()`. Instead, use `expect_snapshot(error = TRUE)` for errors and `expect_snapshot()` for warnings because these allow the user to review the full text of the output.

## Documentation

- Every user-facing function should be exported and have roxygen2 documentation.
- Wrap roxygen comments at 80 characters.
- Internal functions should not have roxygen documentation.
- Whenever you add a new (non-internal) documentation topic, also add the topic to `_pkgdown.yml`.
- Always re-document the package after changing a roxygen2 comment.
- Use `pkgdown::check_pkgdown()` to check that all topics are included in the reference index.

## `NEWS.md`

- Every user-facing change should be given a bullet in `NEWS.md`. Do not add bullets for small documentation changes or internal refactorings.
- Each bullet should briefly describe the change to the end user.
- If the change is related to a function, put the name of the function early in the bullet.
- If the bullet is related to a GitHub issue or pull request, reference it by number in parentheses before the final period: `(#123).`.
- Order bullets alphabetically by function name. Put all bullets that don't mention function names at the beginning.

© Simon P. Couch (@simonpcouch) · MIT · posit-dev/skills

Similar skills

All skills for Programming languages →

From the same set18

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor