Skills r-package-development
install
source · Clone the upstream repo
git clone https://github.com/posit-dev/skills
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/posit-dev/skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/r-lib/r-package-development" ~/.claude/skills/posit-dev-skills-r-package-development && rm -rf "$T"
manifest:
r-lib/r-package-development/SKILL.mdsource content
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
after generating code.air format . - Use the base pipe operator (
) not the magrittr pipe (|>
).%> - Use
for single-line anonymous functions. For all other cases, use\() ...
.function() {...}
Testing
- Tests for
go inR/{name}.R
.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
andexpect_true()
in favour of a specific expectation which will give a better failure message.expect_false() - When testing errors and warnings, don't use
orexpect_error()
. Instead, useexpect_warning()
for errors andexpect_snapshot(error = TRUE)
for warnings because these allow the user to review the full text of the output.expect_snapshot()
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
to check that all topics are included in the reference index.pkgdown::check_pkgdown()
NEWS.md
NEWS.md- Every user-facing change should be given a bullet in
. Do not add bullets for small documentation changes or internal refactorings.NEWS.md - Each bullet should briefly describe the change to the end user and mention the related issue in parentheses.
- A bullet can consist of multiple sentences but should not contain any new lines (i.e. DO NOT line wrap).
- If the change is related to a function, put the name of the function early in the bullet.
- Order bullets alphabetically by function name. Put all bullets that don't mention function names at the beginning.