Data in R Packages

Incorporate exported, internal, and raw data into R packages with CRAN compliance.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides a comprehensive guide to effectively and correctly including data within R packages, ensuring data is accessible, well-documented, and compliant with CRAN policies.

Core Features & Use Cases

  • Data Types: Understand and implement exported data (data/), internal data (R/sysdata.rda), and raw files (inst/extdata/).
  • Documentation: Learn to document datasets using roxygen2 for clarity and discoverability.
  • CRAN Compliance: Adhere to CRAN size limits and best practices for data inclusion.
  • Use Case: You need to include a large dataset in your R package for users to analyze. This Skill will guide you on how to save it, document it, and ensure it doesn't violate CRAN's size restrictions.

Quick Start

Use the Data in R Packages skill to learn how to add a new dataset named 'my_data' to your R package.

Frequently Asked Questions about Data in R Packages

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

FAQPage Schema
How do I include data in an R package?

To include data in an R package, use `usethis::use_data()` to save exported datasets to the `data/` directory, `use_data_raw()` for raw files in `inst/extdata/`, and `R/sysdata.rda` for internal data.

What is the best way to document R package datasets?

Documenting R package datasets requires using `roxygen2` syntax within an `R/data.R` script, which generates the standard help files ensuring your data is discoverable and clearly described for users.

How do I manage internal data vs exported data in R packages?

Manage internal data by saving it to `R/sysdata.rda` using `usethis::use_data(internal = TRUE)`, whereas exported data goes to the `data/` directory to be directly accessible to package users.

Does CRAN have size limits for R package data?

CRAN imposes strict size limitations on R packages, meaning you must carefully manage large datasets, often compressing data or using lazy-loading techniques to ensure your package remains compliant.

When should I use inst/extdata for R package data?

Use `inst/extdata/` for raw files when you need to provide unprocessed source data or examples that users can access via `system.file()`, keeping it separate from formatted exported datasets.

How do I handle dynamic package state management in R?

Handle dynamic package state management in R by utilizing environments, which allow you to store and modify package-level state persistently across user sessions without violating standard scoping rules.