r-package-development

Guide R package development with validation, testing, and roxygen2 documentation.

1|1|Updated May 5, 2026
One-click install
npx skills add https://github.com/cynkra/cynkra.ai.day --skill r-package-development-cynkra
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: r-package-development
Source: https://github.com/cynkra/cynkra.ai.day/tree/main/claude-code-r-skills/.claude/skills/r-package-development
Command: npx skills add https://github.com/cynkra/cynkra.ai.day --skill r-package-development-cynkra

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

R package development becomes error-prone when dependency choices, API contracts, validation, testing, and documentation are handled inconsistently, causing fragile releases and frustrating user experiences.

Core Features & Use Cases

  • Dependency Strategy: Decide when to use base R versus external packages, and structure DESCRIPTION using Imports, Suggests, and other fields.
  • API Design & Input Validation: Apply consistent API patterns (e.g., .by, {{ }}), validate inputs at the right level, and produce actionable error messages.
  • Testing & Documentation Workflow: Organize testthat tests by purpose, ensure exported documentation via roxygen2, and follow a release checklist (devtools::check, test, document, versioning).
  • Release Readiness & Common Pitfalls: Avoid package anti-patterns like library() calls in package code and hardcoded file paths, and finalize checks before publishing.

Quick Start

Ask an AI to review your package plan and then generate a DESCRIPTION dependency approach, roxygen2 documentation stubs for exported functions, a testthat folder layout, and a release checklist tailored to your specific R package idea.

Frequently Asked Questions about r-package-development

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure dependencies in an R package DESCRIPTION file?

Structure R package dependencies by using the Imports field for required packages and Suggests for optional ones. This approach ensures reliable package loading and avoids unnecessary dependency bloat for users.

What is the best way to validate inputs and handle errors in R package API design?

Input validation in R package API design requires checking arguments at the appropriate functional level and returning actionable error messages. Consistent API patterns like `.by` and `{{ }}` ensure predictable, user-friendly function behavior.

How do I organize testthat tests and roxygen2 documentation for an R package?

Organize testthat tests by their specific purpose, such as validation or edge cases, and generate roxygen2 documentation stubs for all exported functions. This ensures comprehensive test coverage and consistent exported documentation.

What should a pre-release checklist include for publishing an R package with devtools?

An R package pre-release checklist should include running `devtools::check`, verifying testthat coverage, updating roxygen2 documentation, and confirming versioning. Finalizing these checks prevents common release pitfalls like hardcoded file paths.

Why should I avoid library() calls inside R package code?

Using `library()` inside R package code is an anti-pattern that modifies the global search path and causes fragile releases. Instead, list dependencies in the DESCRIPTION file and reference them using the `package::function()` syntax.

When should I use base R instead of adding an external package dependency?

Choose base R over external dependencies when the required functionality is simple and stable, reducing the dependency footprint. Evaluate this during API design to keep your R package lightweight and easier to maintain.