R Package Structure

Explains R package directory layouts, build files, and package states.

Updated Feb 15, 2026
One-click install
npx skills add https://github.com/choxos/RPkgAgent --skill r-package-structure
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: R Package Structure
Source: https://github.com/choxos/RPkgAgent/tree/main/plugins/r-package-development/skills/package-structure
Command: npx skills add https://github.com/choxos/RPkgAgent --skill r-package-structure

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill clarifies the complex directory structure and lifecycle states of R packages, ensuring you build robust and well-organized packages.

Core Features & Use Cases

  • Directory Layout: Understand the purpose of R/, man/, tests/, vignettes/, data/, inst/, data-raw/, and src/.
  • Package States: Differentiate between Source, Bundled, Binary, Installed, and In-memory package states.
  • Build Control: Learn how .Rbuildignore and .gitignore manage package contents and version control.
  • Use Case: When starting a new R package, use this Skill to quickly reference the correct placement for functions, tests, data, and documentation files.

Quick Start

Explain the purpose of the R/ directory in an R package.

Frequently Asked Questions about R Package Structure

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

FAQPage Schema
What is the standard directory layout for an R package?

The standard R package directory layout uses R/ for functions, man/ for documentation, tests/ for unit tests, vignettes/ for tutorials, src/ for compiled code, data/ for datasets, and inst/ for miscellaneous files. Each directory serves a specific structural purpose.

How do I configure .Rbuildignore and .gitignore for R package development?

You configure .Rbuildignore to exclude files from the package build bundle and .gitignore to exclude files from version control. Both build control files manage package contents but target different stages of the development lifecycle.

What are the different R package states during the build lifecycle?

R package states differentiate between Source, Bundled, Binary, Installed, and In-memory forms. Understanding these package states clarifies how directory layouts transform into distributable and loadable formats.

Where do I place raw datasets and compiled code in an R package structure?

You place raw datasets in the data-raw/ directory and compiled code in the src/ directory. The data/ directory holds formatted package data, ensuring proper separation of raw inputs and final outputs.

How do I check R package structure and avoid common directory pitfalls?

You check R package structure using usethis helpers and structure checking functions to verify correct directory placement. This avoids common pitfalls like missing required folders or incorrect build configuration file setups.

Do I need a vignettes directory to build a valid R package?

The vignettes/ directory is optional for a valid R package build, whereas R/ and man/ are required. Vignettes provide long-form documentation and tutorials but are not mandatory for basic package states.