r-package-development

Solid

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.

Data & Documents 396 stars 34 forks Updated today MIT

Install

View on GitHub

Quality Score: 91/100

Stars 20%
87
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill 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 `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 r...

Details

Author
posit-dev
Repository
posit-dev/skills
Created
6 months ago
Last Updated
today
Language
R
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category