testing-r-packages

Write R package tests using testthat version 3 and above.

33|Updated Jan 20, 2026
One-click install
npx skills add https://github.com/bbtheo/cuplyr --skill testing-r-packages-bbtheo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-r-packages
Source: https://github.com/bbtheo/cuplyr/tree/main/.claude/skills/testing-r-packages
Command: npx skills add https://github.com/bbtheo/cuplyr --skill testing-r-packages-bbtheo

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance on writing robust, maintainable, and efficient tests for R packages using the testthat package, ensuring code quality and reliability.

Core Features & Use Cases

  • Best Practices: Learn modern testthat 3+ patterns for test structure, organization, and execution.
  • Expectations & Mocking: Master various assertion types, snapshot testing, and mocking external dependencies.
  • Use Case: You are developing an R package and need to ensure your new function calculate_stats() correctly handles various inputs, edge cases, and potential errors. This Skill guides you in writing effective testthat tests to cover these scenarios.

Quick Start

Use the testing-r-packages skill to set up a new R package test suite using testthat 3+.

Frequently Asked Questions about testing-r-packages

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

FAQPage Schema
How do I structure R package tests using testthat 3+?

Structure R package tests using testthat 3+ by organizing tests into self-sufficient blocks, applying modern patterns for expectations, and maintaining proper file hierarchy. This approach ensures robust and maintainable test suites for reliable R development.

What is the best way to handle cleanup in testthat tests?

The best way to handle cleanup in testthat tests is using the withr package to ensure proper teardown of modified environments. This guarantees self-sufficient tests that do not leak state across test cases in your R package.

How does snapshot testing work for R packages?

Snapshot testing for R packages works by capturing the expected output of a function and comparing it against future test runs. This mechanism detects unexpected changes in console output, warnings, or plot rendering efficiently.

Can I mock external dependencies in testthat?

Yes, you can mock external dependencies in testthat to isolate the function under test. Mocking allows you to simulate external API responses or complex object behaviors, ensuring reliable and consistent test execution for your R package.

When should I use testthat fixtures in R development?

Use testthat fixtures in R development when you need to establish a consistent, reusable state across multiple tests. Fixtures help manage setup and teardown processes, ensuring each test runs under identical conditions reliably.